Go Back   The UNIX and Linux Forums > Operating Systems > Solaris


Solaris The Solaris Operating System, usually known simply as Solaris, is a Unix-based operating system introduced by Sun Microsystems. The Solaris OS is now owned by Oracle.

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-22-2013
Registered User
 
Join Date: Aug 2011
Posts: 15
Thanks: 2
Thanked 0 Times in 0 Posts
[Solved] Using awk withing a shell script

I am trying to use an awk command within a ksh script but it is not working - I am able to run from command line with no problem. It does not err out - it just does not produce a file with final count.


Code:
awk "{s+=$0} END {print s}" es.out > es.cnt

Any help would be greatly appreciated. Thanks

Last edited by radoulov; 01-22-2013 at 05:17 PM.. Reason: Marked as solved.
Sponsored Links
    #2  
Old 01-22-2013
Yoda's Avatar
Jedi Master
 
Join Date: Jan 2012
Location: Galactic Empire
Posts: 2,311
Thanks: 154
Thanked 738 Times in 710 Posts
Replace double quotes " with single quotes '

Code:
awk '{s+=$0} END {print s}' es.out

Sponsored Links
    #3  
Old 01-22-2013
Registered User
 
Join Date: Aug 2011
Posts: 15
Thanks: 2
Thanked 0 Times in 0 Posts
I tried that just now - same result.
    #4  
Old 01-22-2013
Mead Rotor
 
Join Date: Aug 2005
Location: Saskatchewan
Posts: 16,407
Thanks: 492
Thanked 2,538 Times in 2,421 Posts
Show the input you have and the output you want.
Sponsored Links
    #5  
Old 01-22-2013
Registered User
 
Join Date: Aug 2011
Posts: 15
Thanks: 2
Thanked 0 Times in 0 Posts
The input is a file with a different number on each line (es.out) - I want to add the numbers for a total in the output file (es.cnt)

HTML Code:
Input - 
 
      252
       428
      1174
        12
        29
       539
        35
        12
        30
         7
         6
         3
         5

 
Output - 
 
2532
Sponsored Links
    #6  
Old 01-22-2013
Mead Rotor
 
Join Date: Aug 2005
Location: Saskatchewan
Posts: 16,407
Thanks: 492
Thanked 2,538 Times in 2,421 Posts
Works fine here, but try $1 instead of $0. Maybe your version of awk refuses to add numbers with whitespace in front of them.
Sponsored Links
    #7  
Old 01-22-2013
Registered User
 
Join Date: Aug 2011
Posts: 15
Thanks: 2
Thanked 0 Times in 0 Posts
Works perfectly now! Thank you so much!!!
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Call shell script function from awk script aishsimplesweet Shell Programming and Scripting 2 08-25-2011 10:42 AM
awk splits file in to multiple - how to get filenames in variables withing ksh? spidermike Shell Programming and Scripting 2 03-17-2010 11:27 AM
create a shell script that calls another script and and an awk script magikminox Shell Programming and Scripting 0 06-26-2008 02:50 AM
html withing shell scripts,how?? divzz Shell Programming and Scripting 6 05-28-2008 08:11 AM
Search withing the line Nafanja Shell Programming and Scripting 4 11-29-2007 12:04 PM



All times are GMT -4. The time now is 01:18 PM.