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
not able to capture STDOUT aks__ UNIX for Dummies Questions & Answers 5 04-25-2008 03:12 AM
stdout back to tty piltrafa UNIX for Dummies Questions & Answers 3 07-03-2007 02:42 PM
cut -d' ' -f7,8 on the stdout of ls -al yongho Shell Programming and Scripting 9 02-15-2007 12:28 PM
stdout redirected? Naanu SUN Solaris 1 02-11-2007 12:03 PM
pipe and stdout vascobrito UNIX for Dummies Questions & Answers 3 02-02-2004 08:20 AM

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 08-05-2006
umen umen is offline
Registered User
  
 

Join Date: Aug 2005
Posts: 239
sum numbers from stdout

hello im looking for short way to sum numbers from stdout the way i found to do it is to long for me i wander if there is shorter way to do it

ok it 2 stage action
this will make the list of number in to file sum.txt

grep -c include *.c | awk '{l=split($0,a,":");print a[2];}' > sum.txt
this will print the sum from the file

awk 'BEGIN {total=0} {total += $1} END {print total}' sum.txt

is there any way to make this action shorter?
  #2 (permalink)  
Old 08-05-2006
ranj@chn ranj@chn is offline Forum Advisor  
Playing with Ubuntu Now!
  
 

Join Date: Oct 2005
Location: Chennai
Posts: 365
merge both actions thru awk

Code:
grep -c include *.c | awk -F: '{total+=$2} END{print total}'
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 04:19 PM.


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