[gentoo-user] Bash script inquiry

2009-08-11 Thread Richard Marza
I'm trying to run a command in a loop. I have a counter device set...the 
number that the counter generates is supposed to go inside the command in 
the loop after every successive iteration of the loop. This is all really to 
get a general idea I've attached a snippet below.


FILE=`cat filename.txt`
TICK=`cat filename.txt | wc -l'
TOCK=0

while [ $TICK != $TOCK ] ; do
   let $TOCK=$TOCK+1
   Var1= `cat FirstWordOfFirstColumnOfFirstLine` (This I actually 
achieved with sed and awk)
   Var2=`cat FirstFloatOfFirstLine`   (The problem lies here; it's 
my inability to come up with a way of implementing a variable that changes 
along with the counter.  so that the second time this is run it doesn't do 
the first line but moved to the second line and the third line and so on...)


done

exit 0



My file is like so:


VariableSys1Sys2Sys3Sys4  Sys5


Dbase1  5.0   4.6  5.6  6. 6   .004







Re: [gentoo-user] Bash script inquiry

2009-08-11 Thread Etaoin Shrdlu
On Tuesday 11 August 2009 09:07:31 Richard Marza wrote:

 I'm trying to run a command in a loop. I have a counter device set...the
 number that the counter generates is supposed to go inside the command in
 the loop after every successive iteration of the loop. This is all really
 to get a general idea I've attached a snippet below.

 FILE=`cat filename.txt`
 TICK=`cat filename.txt | wc -l'
 TOCK=0

 while [ $TICK != $TOCK ] ; do
 let $TOCK=$TOCK+1
 Var1= `cat FirstWordOfFirstColumnOfFirstLine` (This I actually
 achieved with sed and awk)
 Var2=`cat FirstFloatOfFirstLine`   (The problem lies here; it's
 my inability to come up with a way of implementing a variable that changes
 along with the counter.  so that the second time this is run it doesn't do
 the first line but moved to the second line and the third line and so
 on...)

I'm not sure I understand what you want, but you can probably reimplement the 
whole thing in awk or sed only much more efficiently. To get more help on 
that, post a more complete description of the problem and the result you want 
to achieve. 
If you really want to keep the current logic, you can save the nth line of the 
file at iteration n and process it how many times you want:

# line number is in N

nthline=`sed -n $N{p;q;} file.txt`
var1=`echo $nthline | .`
var2=`echo $nthline | .`




Re: [gentoo-user] Bash script inquiry

2009-08-11 Thread Alex Schuster
Richard Marza writes:

 FILE=`cat filename.txt`
 TICK=`cat filename.txt | wc -l'
 TOCK=0

 while [ $TICK != $TOCK ] ; do
 let $TOCK=$TOCK+1

Or, simpler, as we are using bash: (( TOCK++ ))

 Var1= `cat FirstWordOfFirstColumnOfFirstLine` (This I
 actually achieved with sed and awk)
 Var2=`cat FirstFloatOfFirstLine`   (The problem lies here;
 it's my inability to come up with a way of implementing a variable that
 changes along with the counter.  so that the second time this is run it
 doesn't do the first line but moved to the second line and the third line
 and so on...)

 done

 exit 0

What should Var1 contain - Dbase1 or the content of the file Dbase1? 
What should Var2 contain - 5.0or the content of the file 5.0? 
Because you are using cat in the assignment.
If you just need the values in a variable, do it like this:

file=filename.txt
Var1=( $( cat $file | awk '{ print $1 }' ) ) # creates an array variable
Var2=( $( cat $file | awk '{ print $2 }' ) )

The $() notation does the same as backticks, but is more readable. Using 
foo=( ... ) will create foo as an array. I assume there is no whitespace in 
your data, that is Var1 will never contain something like Dbase 1.

${#va...@]} will contain the number of elements (your $TICK). To access the 
5th element (for example), use ${Var1[4]}.

Oh, an please don't hijack threads by replying to an existing one, but start 
a new one. This one appears inside the Cloning movie DVDs thread.

And feel free to ask more questions, maybe I got it all wrong.

Wonko



Re: [gentoo-user] Bash script inquiry

2009-08-11 Thread Richard Marza


- Original Message - 
From: Alex Schuster wo...@wonkology.org

To: gentoo-user@lists.gentoo.org
Sent: Tuesday, August 11, 2009 4:59 AM
Subject: Re: [gentoo-user] Bash script inquiry



Richard Marza writes:


FILE=`cat filename.txt`
TICK=`cat filename.txt | wc -l'
TOCK=0

while [ $TICK != $TOCK ] ; do
let $TOCK=$TOCK+1


Or, simpler, as we are using bash: (( TOCK++ ))


Var1= `cat FirstWordOfFirstColumnOfFirstLine` (This I
actually achieved with sed and awk)
Var2=`cat FirstFloatOfFirstLine`   (The problem lies here;
it's my inability to come up with a way of implementing a variable that
changes along with the counter.  so that the second time this is run it
doesn't do the first line but moved to the second line and the third line
and so on...)

done

exit 0


What should Var1 contain - Dbase1 or the content of the file Dbase1?
What should Var2 contain - 5.0or the content of the file 5.0?
Because you are using cat in the assignment.
If you just need the values in a variable, do it like this:

file=filename.txt
Var1=( $( cat $file | awk '{ print $1 }' ) ) # creates an array variable
Var2=( $( cat $file | awk '{ print $2 }' ) )

The $() notation does the same as backticks, but is more readable. Using
foo=( ... ) will create foo as an array. I assume there is no whitespace 
in

your data, that is Var1 will never contain something like Dbase 1.

${#va...@]} will contain the number of elements (your $TICK). To access 
the

5th element (for example), use ${Var1[4]}.

Oh, an please don't hijack threads by replying to an existing one, but 
start

a new one. This one appears inside the Cloning movie DVDs thread.

And feel free to ask more questions, maybe I got it all wrong.

Wonko



I did not intend to hijack. Next time I will be more cautious. Your 
information is useful. I have used awk. The array is very useful here.


Think of the file I'm using as a spreadsheet. The headers(column names) are 
on top and the values are below them. Each line has an item with multiple 
values under different systems.



Item   System1 System3 System4 ...

nio5.05.55.0(these are individual 
values. They are nothing more than what they represent. The item (nio) and 
the float or integer representing its value under the different 
system...It's just a file)


My goal is to take nio and figure out which system has a different price 
than the others. So if the script were to run through 200 lines of similar 
text it should definitely kick-out: nio has discrepancy in System3; price 
5.5 in line 1



Another thing, all systems can have different prices. This must also kick 
out. This is really a script to report discrepancies. 





Re: [gentoo-user] Bash script inquiry

2009-08-11 Thread Peter Humphrey
On Tuesday 11 August 2009 09:07:31 Richard Marza wrote:
 I'm trying to run a command in a loop. I have a counter device set...the
 number that the counter generates is supposed to go inside the command in
 the loop after every successive iteration of the loop.

In what sense is this a reply to Neil?

Please do not hijack threads.

-- 
Rgds
Peter



[gentoo-user] Bash script inquiry (this is a dup: sorry for the hijack)

2009-08-11 Thread Richard Marza
- Original Message - 
From: Alex Schuster wo...@wonkology.org
To: gentoo-user@lists.gentoo.org
Sent: Tuesday, August 11, 2009 4:59 AM
Subject: Re: [gentoo-user] Bash script inquiry


 Richard Marza writes:

 FILE=`cat filename.txt`
 TICK=`cat filename.txt | wc -l'
 TOCK=0

 while [ $TICK != $TOCK ] ; do
 let $TOCK=$TOCK+1

 Or, simpler, as we are using bash: (( TOCK++ ))

 Var1= `cat FirstWordOfFirstColumnOfFirstLine` (This I
 actually achieved with sed and awk)
 Var2=`cat FirstFloatOfFirstLine`   (The problem lies here;
 it's my inability to come up with a way of implementing a variable that
 changes along with the counter.  so that the second time this is run it
 doesn't do the first line but moved to the second line and the third line
 and so on...)

 done

 exit 0

 What should Var1 contain - Dbase1 or the content of the file Dbase1?
 What should Var2 contain - 5.0or the content of the file 5.0?
 Because you are using cat in the assignment.
 If you just need the values in a variable, do it like this:

 file=filename.txt
 Var1=( $( cat $file | awk '{ print $1 }' ) ) # creates an array variable
 Var2=( $( cat $file | awk '{ print $2 }' ) )

 The $() notation does the same as backticks, but is more readable. Using
 foo=( ... ) will create foo as an array. I assume there is no whitespace 
 in
 your data, that is Var1 will never contain something like Dbase 1.

 ${#va...@]} will contain the number of elements (your $TICK). To access 
 the
 5th element (for example), use ${Var1[4]}.

 Oh, an please don't hijack threads by replying to an existing one, but 
 start
 a new one. This one appears inside the Cloning movie DVDs thread.

 And feel free to ask more questions, maybe I got it all wrong.

 Wonko


I did not intend to hijack. Next time I will be more cautious. Your 
information is useful. I have used awk. The array is very useful here.

Think of the file I'm using as a spreadsheet. The headers(column names) are 
on top and the values are below them. Each line has an item with multiple 
values under different systems.


Item   System1 System3 System4 ...

nio5.05.55.0(these are individual 
values. They are nothing more than what they represent. The item (nio) and 
the float or integer representing its value under the different 
system...It's just a file)

My goal is to take nio and figure out which system has a different price 
than the others. So if the script were to run through 200 lines of similar 
text it should definitely kick-out: nio has discrepancy in System3; price 
5.5 in line 1


Another thing, all systems can have different prices. This must also kick 
out. This is really a script to report discrepancies. 

Hopefully this one does not appear to be hijacked. If it is let me know and 
I'll stop the discussion with regards to my inquiry. Thank you.


Re: [gentoo-user] Bash script inquiry

2009-08-11 Thread Etaoin Shrdlu
On Tuesday 11 August 2009 10:27:26 Richard Marza wrote:

 Think of the file I'm using as a spreadsheet. The headers(column names) are
 on top and the values are below them. Each line has an item with multiple
 values under different systems.


 Item   System1 System3 System4 ...

 nio5.05.55.0(these are individual
 values. They are nothing more than what they represent. The item (nio) and
 the float or integer representing its value under the different
 system...It's just a file)

 My goal is to take nio and figure out which system has a different price
 than the others. So if the script were to run through 200 lines of similar
 text it should definitely kick-out: nio has discrepancy in System3; price
 5.5 in line 1


 Another thing, all systems can have different prices. This must also kick
 out. This is really a script to report discrepancies.

As I suspected, you can do the whole thing in awk only. Basically, I'm going 
to assume you want to report items which don't have all the same values on all 
systems. It's easy to spot those, but it might not be as easy to determine 
which values are the normal ones and which are the discrepant ones, 
especially if for example each system has a different value. You have to 
provide additional logic to tell the discrepant values from the others. For 
the moment, the script just prints out the lines where all the columns don't 
have the same value.

awk 'NR==1{print;next}{for(i=3;i=NF;i++){if($i!=$2){print;break}}}' file.txt  




Re: [gentoo-user] Bash script inquiry

2009-08-11 Thread Richard Marza


- Original Message - 
From: Etaoin Shrdlu shr...@unlimitedmail.org

To: gentoo-user@lists.gentoo.org
Sent: Tuesday, August 11, 2009 5:55 AM
Subject: Re: [gentoo-user] Bash script inquiry



On Tuesday 11 August 2009 10:27:26 Richard Marza wrote:

Think of the file I'm using as a spreadsheet. The headers(column names) 
are

on top and the values are below them. Each line has an item with multiple
values under different systems.


Item   System1 System3 System4 ...

nio5.05.55.0(these are individual
values. They are nothing more than what they represent. The item (nio) 
and

the float or integer representing its value under the different
system...It's just a file)

My goal is to take nio and figure out which system has a different 
price
than the others. So if the script were to run through 200 lines of 
similar
text it should definitely kick-out: nio has discrepancy in System3; 
price

5.5 in line 1


Another thing, all systems can have different prices. This must also kick
out. This is really a script to report discrepancies.


As I suspected, you can do the whole thing in awk only. Basically, I'm 
going
to assume you want to report items which don't have all the same values on 
all

systems. It's easy to spot those, but it might not be as easy to determine
which values are the normal ones and which are the discrepant ones,
especially if for example each system has a different value. You have to
provide additional logic to tell the discrepant values from the others. 
For
the moment, the script just prints out the lines where all the columns 
don't

have the same value.

awk 'NR==1{print;next}{for(i=3;i=NF;i++){if($i!=$2){print;break}}}' 
file.txt



This is great. But it is important that I find which system has a mismatch 
for each item. I guess this is where loops and if statements come in. I 
believe I have sufficient information. Although, more discussion is welcome. 
Thank you all.





Re: [gentoo-user] Bash script inquiry

2009-08-11 Thread Etaoin Shrdlu
On Tuesday 11 August 2009 11:17:12 Richard Marza wrote:

  For the moment, the script just prints out the lines where all the columns
  don't have the same value.
 
  awk 'NR==1{print;next}{for(i=3;i=NF;i++){if($i!=$2){print;break}}}'
  file.txt

 This is great. But it is important that I find which system has a mismatch
 for each item. I guess this is where loops and if statements come in. I
 believe I have sufficient information. Although, more discussion is
 welcome. Thank you all.

If you have a way to tell regular values from discrepant ones, it's easy to 
modify the program to account for that and print only the values of discrepant 
columns. One way could be to look for the value that appears most times in a 
row, and consider that value normal and all the others discrepant. But again, 
you could have two values repeated the same number of times, so that would not 
help. That's why it's important to have an unambiguous rule.