[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

try something like this,

printf "%d, %d\n", cd, cs_cd[cd]

hi matrix,

not working

output :

123, 0
133, 0

any idea?

thank you

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

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:

$ 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 ...):

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:

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

its work

thank you