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



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
Format output using awk in script. bperl Shell Programming and Scripting 8 01-14-2008 01:09 AM
Output in a particular format using AWK Raynon Shell Programming and Scripting 4 01-24-2007 04:07 AM
format output Tornado Shell Programming and Scripting 7 11-19-2006 06:17 AM
ls output format tonyt UNIX for Dummies Questions & Answers 6 11-23-2001 11:31 AM

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 02-08-2007
bucci bucci is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 81
Question [need help] output format from awk

hi all,

i have a problem with my nawk command output below is the description :

nawk $12 == "00008001" { cnt++;cs_cd[$11] } END {for(cd in cs_cd) print cd, cs_cd[cd] } 2007020814.TDR

output :

133
123

desire output:

133,123,....

please advices


thank you so much

Regards,

bucci
  #2 (permalink)  
Old 02-08-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,953
Quote:
print cd, cs_cd[cd]

try something like this,

Code:
printf "%d, %d\n", cd, cs_cd[cd]
  #3 (permalink)  
Old 02-08-2007
bucci bucci is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 81
Quote:
Originally Posted by matrixmadhan
try something like this,

Code:
printf "%d, %d\n", cd, cs_cd[cd]
hi matrix,

not working

output :

123, 0
133, 0

any idea?

thank you
  #4 (permalink)  
Old 02-08-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,953
Really I dont know about the input file (the format) that you are using.

If possible could you please post examples from your input file.
  #5 (permalink)  
Old 02-08-2007
bucci bucci is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 81
Quote:
Originally Posted by matrixmadhan
Really I dont know about the input file (the format) that you are using.

If possible could you please post examples from your input file.
hi matrix,

the input file is:

20070208 163020.951 20070208 163021.163 000.212 6211111111111 00000803 005 02 002 123 00008001 511000000000000 ---
20070208 164008.211 20070208 164008.433 000.222 6211111111111 00000804 004 02 002 123 00008001 511000000000000 ---
20070208 164508.096 20070208 164508.305 000.209 6211111111111 00000805 006 02 002 133 00008001 511000000000000 ---
20070208 165802.461 20070208 165802.653 000.192 6211111111111 00000806 005 02 002 133 00008001 511000000000000 ---

any idea?

thank you
  #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,859
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..
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 01:43 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