LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Bash change the items in comparisons with simple front end (https://www.linuxquestions.org/questions/programming-9/bash-change-the-items-in-comparisons-with-simple-front-end-625602/)

geeyathink 03-04-2008 06:56 AM

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


ntubski 03-04-2008 07:03 PM

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.

chrism01 03-04-2008 07:12 PM

1. You seem to have 2 line 16's
2. the first line 16 uses '....mfile_$i', but $i has not been set yet.....

geeyathink 03-04-2008 09:53 PM

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.


All times are GMT -5. The time now is 03:28 AM.