I have a file with the following values:
ID1 RID1 2 rid1 part2 ID1 RID2 1 rid2 part1 ID1 RID2 2 rid2 part2 ID2 RID3 1 rid3 part1 ID2 RID3 2 rid3 part2 ID2 RID4 1 rid4 part1
ID RID Offset Text. ID, RID, Offset and Text are tab delimited. The text can be multiple words with spaces in between.
I am trying to concatenate them based on RID and ascending offset.
Essentially the desired output is
ID2 RID3 rid3 part1rid3 part2 ID2 RID4 rid4 part1 ID1 RID1 rid1 part1rid1 part2 ID1 RID2 rid2 part1rid2 part2
I am trying to do this with awk. Here is my awk 1 liner:
cat example.txt| awk '{line=""; line = line $4; table[$1"\t"$2]=table[$1"\t"$2] line;} END {for (key in table) print key"\t"table[key];}'
For some reason, awk is not able to parse all the words in $4, i.e, it is just picking the 1st word and outputting:
ID2 RID3 rid3rid3 ID2 RID4 rid4 ID1 RID1 rid1rid1 ID1 RID2 rid2rid2
How do I parse all the words in $4 and not just the 1st word?
awk -F "\t"
to set the field separator to tab rather than any combination of spaces and tabs as is the default? – Jules