The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
search for the contents in many file and print that file using shell script cdfd123 Shell Programming and Scripting 3 10-07-2007 11:17 PM
Creating file contents using contents of another file ReV Shell Programming and Scripting 21 02-24-2006 10:25 AM
How to adding the filename into file contents missutoomuch Shell Programming and Scripting 2 11-11-2005 05:26 AM
Reading specific contents from a file and appending it to another file dnicky Shell Programming and Scripting 5 10-04-2005 06:45 AM
adding contents of a variable to a command gammarays Shell Programming and Scripting 2 02-08-2005 01:39 PM

Closed Thread
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 05-25-2006
dakid dakid is offline
Registered User
  
 

Join Date: May 2006
Posts: 27
adding contents of file

for example i have a file which contains data like:


123
222
325
142

can anyone help me write a script that adds them?
let's say that "total" is the filename...
  #2 (permalink)  
Old 05-25-2006
ranj@chn ranj@chn is offline Forum Advisor  
Playing with Ubuntu Now!
  
 

Join Date: Oct 2005
Location: Chennai
Posts: 365
man awk

check awk.

Code:
awk '{sum+=$1} END{printf("%d\n",sum)}' filename

Always do a search in the forum. You will find your answer.
  #3 (permalink)  
Old 10-20-2006
alfredo123 alfredo123 is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 44
The above did not do a sum including the decimals...it just did a sum and rounded of the decimals!

Is there a way to do sum which includes the decimals?
  #4 (permalink)  
Old 10-20-2006
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398

Code:
awk '{sum+=$1} END{printf("%f\n",sum)}' filename

  #5 (permalink)  
Old 10-20-2006
alfredo123 alfredo123 is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 44
Quote:
Originally Posted by anbu23
Code:
awk '{sum+=$1} END{printf("%f\n",sum)}' filename
Awesome! Thanks Anbu...
Closed Thread

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 11:43 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