I've the following sample input format (file or stdin):
key1: 1
key2: 2
key3: 3
key1: 4
key2: 5
key3: 6
Is there any few-liner which can group values based on the key and then sort?
Expected output would be either table:
key1 key2 key3
1 2 3
4 5 6
which can be afterwards sorted by column (e.g. sort -k2
). Similar to this example.
Or in similar format, like:
key1: 1 4
key2: 2 5
key3: 3 6
What's the easiest way to achieve that transformation?
sort -k1,1 -k2
) which also would result in sorted values (so you could justsort
without any-k
option), then the problem is simplified to merging lines with the same prefix; see unix.stackexchange.com/questions/47786/…