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
Reading numbers thru shell bhagyaraj.p Shell Programming and Scripting 2 04-14-2009 12:22 PM
Shell script to search through numbers and print the output cdfd123 Shell Programming and Scripting 8 10-30-2007 04:40 PM
Shell script to check the unique numbers in huge data namishtiwari Shell Programming and Scripting 7 08-10-2007 10:38 AM
retain Line numbers.. in Vi .. OR .. A SHELL SCRIPT sdlayeeq Shell Programming and Scripting 2 04-26-2005 05:20 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 07-25-2006
Terrible
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
add numbers in shell script

cat dailyreports | grep "Important list" | awk -F":" '{print $2}' | awk -F" " '{print $1}'

hey guys, after running the above combination of cat and awk, i get the below output:

3
4
2
9

now, i need to add these numbers up all in one line. i dont know what to add to that cat and awk one liner to accomplish this addition. can someone please help me? thanks
  #2 (permalink)  
Old 07-25-2006
Klashxx's Avatar
Klashxx Klashxx is offline Forum Advisor  
HP-UX/Linux/Oracle
  
 

Join Date: Feb 2006
Location: Almerķa, Spain
Posts: 393
Try
Code:
awk -F":" '/Important list/ {print $2}' dailyreports | awk '{print $1}'|while read w
do
   line="${line}${w}"
done

echo ${line}
Or in awk:
Code:
awk '
BEGIN {FS=":"}
{
	if ( $0 ~ /Important list/ )
		c=substr($2,1,1)c
}
END {print c} ' dailyreports

Last edited by Klashxx; 07-25-2006 at 09:35 AM..
  #3 (permalink)  
Old 07-25-2006
grial's Avatar
grial grial is offline Forum Advisor  
El UNIX es como un toro
  
 

Join Date: Jun 2006
Location: Madrid (Spain)
Posts: 531
or
Code:
grep "Important list" dailyreports| awk -F":" '{print $2}' | awk '{print $1}'| while read l; do echo -e "$l \c"; done
Which is almost the same Klashxx says in his first example
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 09:49 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