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




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #6 (permalink)  
Old 02-08-2007
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,875
I don't understand what exactly you're trying to accomplish
with your script, but with ORS="," you'll get an extra "," and no new line at the end:

Code:
$ nawk '$12=="00008001"{!cs_cd[$11]++}END{for(cd in cs_cd)print cd}' ORS="," infile
133,123,
BTW if you want to preserve the order (123, 133 ...):

Code:
nawk '$12=="00008001"&&!x[$11]++{print $11}' ORS="," infile

Given your original code (and not the sample output)
it _seems_ you want something like this:

Code:
nawk '$12=="00008001"{cs_cd[$11]++}END{for(cd in cs_cd)print cd,cs_cd[cd] }' ORS="," infile

Last edited by radoulov; 02-08-2007 at 07:52 AM..