LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 03-04-2008, 06:56 AM   #1
geeyathink
Member
 
Registered: Apr 2006
Distribution: Mandy 2007, Kubuntu
Posts: 56

Rep: Reputation: 15
Bash change the items in comparisons with simple front end


This is a trimmed and scaled down portion of the script I am working on.

I am trying to figure out how to get it to post properly on my website using kompoZer so anyone could look at the whole of it to help me, if they are willing. But until then.

It is a learning experiance for me and hopefully will be useful for me when its done. I know it needs a huge amount of cleaning (if not just thrown out!).

I started making a simple front end (if I am using the term correctly). Thats when I realized the comparison part of the script (lines 30-48) is not yet easily configurable for me.
I think I will be able, using the basic tools and constructs in a script, to change the number and content of the various lists that are being used and to feed them into the script. But when it comes to the comparison part I don't know how to proceed.

I am guessing that some form of nested loop would be best,(but of course, I have yet to be correct about anthing)

I would like to be able to change the value and the shear number of the different categories that are being parsed for. I may only want to parse for the three categories that are shown here
but I may want to parse for twenty different categories.

Please offer up the good ways to make the comparison part of this configurable. I would like to stick with bash and the basics because that is after all what I am trying to learn at this time.

Please start with just the ideas don't post a finished script. Obviously I haven't been able to figure it out on my own but if you say it will definatly
work using "name an idea" I will bang my head against man and google some more on that specific idea.

Thanks for any help, I am going to ask for general cleanup help with it when I can get it to post proper on my website.

Code:
3	#!/bin/bash
4	exec 2>/home/teabear/zmyworkspace/script1.log
5	set -x
6	
7	IFS="
8	"
9	kdialog -passivepopup "started" 4
10	
11	elist=/home/teabear/bashwork/indvlist/electriclist
12	folist=/home/teabear/bashwork/indvlist/foodlist
13	plist=/home/teabear/bashwork/indvlist/puterlist
14	
15	sort -m -o /home/teabear/bashwork/mfilelist/mfile $elist $plist $folist
16	cp /home/teabear/bashwork/mfilelist/mfile /home/teabear/bashwork/troubleshooting/parsingfiles/mfile_$i
16
17	for i in `ls /home/teabear/bashwork/dragto`; do
18	grep -awio -f /home/teabear/bashwork/mfilelist/mfile /home/teabear/bashwork/dragto/$i | cat > /home/teabear/bashwork/extractedlist
19	
20	phit=`grep -ioc -f /home/teabear/bashwork/indvlist/puterlist /home/teabear/bashwork/extractedlist`
21	ehit=`grep -ioc -f /home/teabear/bashwork/indvlist/electriclist /home/teabear/bashwork/extractedlist`
22	fohit=`grep -ioc -f /home/teabear/bashwork/indvlist/foodlist /home/teabear/bashwork/extractedlist`
23	
24	fofold=/home/teabear/bashwork/destinationfolders/food          
25	pfold=/home/teabear/bashwork/destinationfolders/puter
26	efold=/home/teabear/bashwork/destinationfolders/electric
27	
28	acon=/home/teabear/bashwork/dragto/$i
29	
30	if [ "$ehit" -gt "$fohit" ] && [ "$ehit" -gt "$phit" ] 
31	   then kdialog -passivepopup "$i file will be moved to Electrical folder" 2
32	        cp /home/teabear/bashwork/extractedlist /home/teabear/bashwork/troubleshooting/parsingfiles/extractedlist_$i
33	        mv $acon $efold
35	
36	     elif [ "$fohit" -gt "$ehit" ] && [ "$fohit" -gt "$phit" ] 
37	     then kdialog -passivepopup "$i file will be moved to Culinary folder" 2
38	          cp /home/teabear/bashwork/extractedlist /home/teabear/bashwork/troubleshooting/parsingfiles/extractedlist_$i
39	          mv $acon $fofold
41	
42	          elif [ "$phit" -gt "$fohit" ] && [ "$phit" -gt "$ehit" ] 
43	          then kdialog -passivepopup "$i file will be moved to Puter folder" 2
44	               cp /home/teabear/bashwork/extractedlist /home/teabear/bashwork/troubleshooting/parsingfiles/extractedlist_$i
45	               mv $acon $pfold
47	
48	fi
49	done
50	
51	kdialog -msgbox "end"
52	
53
 
Old 03-04-2008, 07:03 PM   #2
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 2,308

Rep: Reputation: 768Reputation: 768Reputation: 768Reputation: 768Reputation: 768Reputation: 768Reputation: 768
It looks like the comparison part of the script (lines 30-48) is trying to find the maximum hits. You could find the max by sorting and taking the last, or more efficiently by looping over the list once, keeping the largest number so far.
 
Old 03-04-2008, 07:12 PM   #3
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5
Posts: 16,086

Rep: Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995
1. You seem to have 2 line 16's
2. the first line 16 uses '....mfile_$i', but $i has not been set yet.....
 
Old 03-04-2008, 09:53 PM   #4
geeyathink
Member
 
Registered: Apr 2006
Distribution: Mandy 2007, Kubuntu
Posts: 56

Original Poster
Rep: Reputation: 15
Thank you both for the thoughts and suggestions.

Yes, I had been making copies of the "mfile" along with copies of the "extracted" lists. Then I realized only one copy of the master list (mfile) would be needed as it remains the same for the entire run. I removed it from where it had been(with each elif) and just put it once at the top but got it to far up by accident. I will move it to a better location.

Thanks again very much.

I am off to ponder.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple bash script "unexpected end of line error" snowman81 Programming 11 11-11-2007 09:31 AM
date comparisons and increments in bash elinenbe Programming 5 10-19-2007 11:40 AM
creating a simple GTK-based front-end bpk Programming 3 05-13-2005 01:50 PM
java front end using bash, cdrecord, cd peranioia, and .flac xviddivxoggmp3 Programming 2 08-12-2004 08:54 PM
after a web front end acid_kewpie Linux - Networking 1 08-15-2002 05:51 PM


All times are GMT -5. The time now is 07:18 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration