
April 19th, 2005, 01:39 AM
|
|
Contributing User
|
|
Join Date: Dec 2004
Location: Prague, Czech Rep.
Posts: 116
  
Time spent in forums: 22 h 34 sec
Reputation Power: 6
|
|
Quote: | Originally Posted by Enigma23 Given the 2 attached files, I need to calculate which shipper had the most business ( the values under freight in ShippingOrders.tab file) using csh. I thought that the script i created below would give me the totals but it displays nothing. Can someone tell me how to get these values to be displayed? Thanks.
Here is my script:
Code:
set count = 6 # bc there are 5 shippers total
set num = 1
while($num < $count)
awk '{if($2 ~/$num/) {x+=$5}} END{print x}' ShippingOrders.tab
@ num = $num + 1
end
|
Hello,
I do not know the csh so I might be wrong. I think that you should read the standard input and then pipe the lines into the awk.
In sh or ksh or bash the loop would be :
while read LINE; do
echo $LINE | awk ...
done
Bur here you are calling the awk five times. So you would get five results (possibly empty). The correct way is to pump the standard input directly into the awk, like this:
cat | awk ....
or simply
awk ....
Regards 
|