I have a table that looks like
'a;b;f|d;e;c|g;h'
which I wish to sort by the third column. The output should be
'g;h|d;e;c|a;b;f'
If I were to use the standard delimiters whitespace and newline then this could be accomplished using standard sort:
printf '%b' 'a b f\nd e c\ng h' | sort -k 3
would output
g h
d e c
a b f
The sort command can also take a non standard field separator with the -t option:
printf '%b' "a;b;f\nd;e;c\ng;h" | sort -k 3 -t ';'
would output
g;h
d;e;c
a;b;f
I have however failed to find a way to sort a table with a non-newline record separator.
Can this be accomplished? If so, how?
Edit
A key condition is to alter neither data nor delimiters in the process, only the order in which they appear.
Other tools than the sort command are also ok. Preferably POSIX compliant, but not necessarily.
sortthen. The man page says 'The sort utility sorts text and binary files by lines. A line is a record separated from the subsequent record by a newline (default) or NUL '\0' character'\nor\0, sort is of no help to you. What ever other tools that you could use Awk/Perl or GNU datamash all rely on knowing what the delimiter is|and sorts it (like my answer)