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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Stumped JeffR Shell Programming and Scripting 3 05-30-2008 06:01 PM
RegEx question has me stumped tolmark UNIX for Dummies Questions & Answers 7 08-18-2007 03:20 PM
httpd.conf - stumped Cameron IP Networking 2 04-25-2002 02:31 AM

Reply
 
LinkBack Thread Tools Display Modes
  #8 (permalink)  
Old 05-19-2008
Moderator
 

Join Date: Feb 2007
Posts: 1,665
Piping the output to sort?
Reply With Quote
Forum Sponsor
  #9 (permalink)  
Old 05-19-2008
Registered User
 

Join Date: Jan 2008
Posts: 63
If I do that, the headers get moved around and don't "line-up" with the awk elements.
Reply With Quote
  #10 (permalink)  
Old 05-19-2008
Moderator
 

Join Date: Feb 2007
Posts: 1,665
O my, I only read the last 2 post and did'nt look at the desired output, I apologize.
Reply With Quote
  #11 (permalink)  
Old 05-19-2008
Registered User
 

Join Date: Jan 2008
Posts: 63
does anyone know how to use the system command in awk? Been trying to sort with the following:

Code:
END {
for ( i in x )
if ( i != "0-0" ) {
printf "%s",i | system("sort -nk 1") }
can't get it working so that I can sort these arrays
Reply With Quote
  #12 (permalink)  
Old 05-19-2008
rubin's Avatar
Registered User
 

Join Date: Nov 2007
Posts: 151
Use sort without the AWK system function:

Code:
...
printf "%s",i | "sort -nk 1" }
Reply With Quote
  #13 (permalink)  
Old 05-20-2008
Registered User
 

Join Date: Jan 2008
Posts: 63
Thanks ruben.

I am still having issues with sorting these arrays with awk. This is what I have now:

Code:
END {
for ( i in x )
if ( i != "0-0" ) {
printf "%s\n",i | "sort -nk 1 > /tmp/a.out 2>&1"}
while ( (getline < "/tmp/a.out") > 0 )
sort[$1]
for ( s in sort )
printf "%s\n",s }
I was hoping that awk printed out indices in the order received. When I check "/tmp/a.out" indices ARE in sorted order, but when I re-assign and loop thru them, they are not.

Any awkologist that can help would be very much appreciated.

Thanks
Reply With Quote
  #14 (permalink)  
Old 05-20-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,094
for (s in sort) basically randomizes the order in which they are processed. So, as the doctor said, "don't do that then".
Reply With Quote
Google UNIX.COM
Reply

Tags
linux

Thread Tools
Display Modes




All times are GMT -7. The time now is 02:23 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0