I\'ve got an input file (input.txt) with a few fields:
A1 B1 C1 D1 E1
A2 B2 C2 D1 E2
A3 B3 C3 D2 E3
A4 B4 C4 D2 E4
And I wa
Your output isn't consistent with your command, but I assume that you want the following:
A naïve fix to get what you want would be:
$ awk '{a[$4]=a[$4] " " $5} END {for (b in a) { print b; print a[b]}}' input.txt
D1
E1 E2
D2
E3 E4
but there are two things to note:
for (b in a)
, the 4th-column values will NOT appear in the order they appear in the input, because the order in which awk
enumerates keys of its [always associative] arrays is based on internal hash values, which has no guaranteed relationship to the order in which array elements were added (nor does it guarantee any particular order in general).