[Solved] Using awk withing a shell script | Unix Linux Forums | Solaris

  Go Back    


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.

[Solved] Using awk withing a shell script

Solaris


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-22-2013
bjdamon bjdamon is offline
Registered User
 
Join Date: Aug 2011
Last Activity: 17 April 2014, 12:07 PM EDT
Posts: 21
Thanks: 3
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 06:17 PM.. Reason: Marked as solved.
Sponsored Links
    #2  
Old 01-22-2013
Yoda's Avatar
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 21 November 2014, 11:17 AM EST
Location: Galactic Empire
Posts: 3,389
Thanks: 235
Thanked 1,210 Times in 1,136 Posts
Replace double quotes " with single quotes '

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

Sponsored Links
    #3  
Old 01-22-2013
bjdamon bjdamon is offline
Registered User
 
Join Date: Aug 2011
Last Activity: 17 April 2014, 12:07 PM EDT
Posts: 21
Thanks: 3
Thanked 0 Times in 0 Posts
I tried that just now - same result.
    #4  
Old 01-22-2013
Corona688 Corona688 is online now Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 24 November 2014, 5:17 PM EST
Location: Saskatchewan
Posts: 19,925
Thanks: 846
Thanked 3,417 Times in 3,202 Posts
Show the input you have and the output you want.
Sponsored Links
    #5  
Old 01-22-2013
bjdamon bjdamon is offline
Registered User
 
Join Date: Aug 2011
Last Activity: 17 April 2014, 12:07 PM EDT
Posts: 21
Thanks: 3
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
Corona688 Corona688 is online now Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 24 November 2014, 5:17 PM EST
Location: Saskatchewan
Posts: 19,925
Thanks: 846
Thanked 3,417 Times in 3,202 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
bjdamon bjdamon is offline
Registered User
 
Join Date: Aug 2011
Last Activity: 17 April 2014, 12:07 PM EDT
Posts: 21
Thanks: 3
Thanked 0 Times in 0 Posts
Works perfectly now! Thank you so much!!!
Sponsored Links
Closed Thread

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 11: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 12:27 PM
create a shell script that calls another script and and an awk script magikminox Shell Programming and Scripting 0 06-26-2008 03:50 AM
html withing shell scripts,how?? divzz Shell Programming and Scripting 6 05-28-2008 09:11 AM
Search withing the line Nafanja Shell Programming and Scripting 4 11-29-2007 01:04 PM



All times are GMT -4. The time now is 06:31 PM.