The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 08-20-2009
EAGL€ EAGL€ is offline
Registered User
  
 

Join Date: Aug 2009
Location: istanbul
Posts: 46
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
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:29 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0