I've been trying to find a way of sorting this with standard commandline tools, bash, awk, sort, whatever but can't find a way apart from using perl or similar.
Any hint?
Input data
header1
3
2
5
1
header2
5
1
3
.....
.....
Output data
header1
1
2
3
5
header2
1
....
Thanks
Use AWK to prefix the
header
to each number line.sort
the resulting file.remove the prefix to return the file to original format.
with GNU awk, you can use its internal sort functions.
output
Try this:
To get rid of the blank lines, I guess you can add a "| grep -v '^$'" at the end...
Assumes sections are separated by blank lines and the header doesn't necessarily contain the string "header". Leaves the sections in the original order so the sort is stable. Reads from stdin, displays on stdout.
Or as a one-liner: