Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

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

share|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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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