The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
regular expression format string in one line. jimmy_y Shell Programming and Scripting 2 3 Weeks Ago 10:30 PM
its been a while, but its comming back! flyboy High Level Programming 2 05-01-2009 02:06 AM
how to use regular expression in Bash Shell Scripting sunitachoudhury Shell Programming and Scripting 5 03-13-2008 01:12 AM
problem with comming out on internet steffa UNIX for Advanced & Expert Users 1 09-13-2004 09:30 AM
regular expression format trynew Shell Programming and Scripting 1 06-21-2002 12:26 PM

Reply
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
  #1 (permalink)  
Old 3 Weeks Ago
rveri rveri is offline
Registered User
  
 

Join Date: Sep 2009
Posts: 9
scripting/awk help : awk sum output is not comming in regular format. Pls advise.

Hi Experts,

I am adding a column of numbers with awk , however not getting correct output:

# awk '{sum+=$1} END {print sum}' datafile
2.15291e+06

How can I getthe output like : 2152910


Thank you..





Code:
 
# awk '{sum+=$1} END {print sum}' datafile 
2.15079e+06

#cat datafile
36171
3832
1361
1229
56096
1629
4421
3654
118455
52231
51299
188963
55128
105351
1229
1606
109271
13050
150202
92293
1157
54625
163311
1253
45338
628891
1357
209511
  #2 (permalink)  
Old 3 Weeks Ago
Scrutinizer Scrutinizer is online now
Registered User
  
 

Join Date: Nov 2008
Posts: 676
Code:
awk '{sum+=$1} END {printf "%.f\n",sum}' datafile
Bits Awarded / Charged to Scrutinizer for this Post
Date User Comment Amount
3 Weeks Ago rveri N/A 20
  #3 (permalink)  
Old 3 Weeks Ago
rveri rveri is offline
Registered User
  
 

Join Date: Sep 2009
Posts: 9
Scrutinizer ,
nice ..working Thanks.
  #4 (permalink)  
Old 3 Weeks Ago
Skaperen Skaperen is offline
Registered User
  
 

Join Date: Sep 2009
Posts: 4
If all the numbers are integers, you can use %d (or %u if always positive) instead of %.f
Reply

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 06:22 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