![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Sequential comparison (one row with file and so on) | Gery | Shell Programming and Scripting | 2 | 06-02-2009 12:15 PM |
| Runnin Sequential commands | silk_eye | Shell Programming and Scripting | 5 | 06-05-2007 06:28 AM |
| Sequential execution of job in cron | pankajkrmishra | Shell Programming and Scripting | 3 | 08-15-2006 06:19 AM |
| Reading special characters while converting sequential file to line sequential | Rajeshsu | High Level Programming | 2 | 07-10-2006 03:38 PM |
| running script sequential | ocjunky | Shell Programming and Scripting | 2 | 06-13-2006 04:46 AM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
AWK help to add up sequential values
Hello All! As a beginner user i want to add up sequential values in a text file and want to print total sum as output.The Text file will have values like the following: class1{root}>less SUM.txt 1140.00 1155.00 1183.00 ... # it continues # i tried to write a script with for-do looping and awk inside the loop but it didnt work (not a surprise to me ) And i dont know how to end up the looping as it should detect the last value in file (for ex: if there is 5 values it should stop when AWK detects that 6th value is zero). Could you help me please..Code:
for (( i=1; i<=100; i++ )) do
cat SUM.txt | awk '{total += $i} END {printf "%15.2f\n",total}'
if [ "$awk'{printf "%15.2f\n",total}" -eq 0 ]
then break ## or end up the loop and print the result ##
fi
done
Last edited by EAGL€; 08-20-2009 at 02:30 PM.. |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|