0

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.

  • 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
0

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.

  • 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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