I'm on Windows and have only heard of linuxes awk etc so I can only imagine that this is possible without actual scripting:

I have data like

..
162     42      A single serving
162     62      of french fries, please
164     -1      ABC
164     -1      1
..

that I would like to be turned into

..
A single serving of french fries, please
..

so the rule would be

merge third columns for identical first columns when second column >= 0.

I'll try to find awk for Windows.

link|improve this question
Here's GNU awk for Windows (download dependencies as well). – none Aug 31 '11 at 15:02
gawk "$2 >= 0 { print $3 }" txt.txt gives me the strings I want, but not yet grouped by the first column.. – none Aug 31 '11 at 15:06
feedback

1 Answer

up vote 0 down vote accepted

Use arrays to build up the strings:

awk -F '\t' '
  $2 >= 0 {str[$1] = str[$1] $3 " "}
  END {for (s in str) print str[s]}
' filename

I hope your data is actually tab-separated because otherwise $3 == "A" for the first line.

link|improve this answer
Fantastic. This works on Windows gawk -F "\t" "$2 >= 0 {str[$1] = str[$1] $3 \" \"} END {for (s in str) print str[s]} " %1 – none Aug 31 '11 at 15:27
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.