1
1
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?
Assuming the initial key sort (
– michael – 2015-05-03T08:58:09.827sort -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 http://unix.stackexchange.com/questions/47786/concatenate-lines-by-first-column-awk-or-sed