2
I'm trying to sort the output of the md5sum
program by file name, numerically (that is, file names all match log-\d+\.txt
). I tried
sort -g "-t " -k 2 CHECKSUMS
but it sorts by checksum. Using
sort "-t " -k 2 CHECKSUMS
does sort by filename, but log-12.txt
is placed before log-2.txt
.
Any clues? Thanks!
What if the number of dashes was not the same in every file (e.g.
a-1, a-2, a-a-1, b-1, b-a-a-1, b-a-b-1, b-a-b-2, ...
)? Is there a way to tell sort to start comparing numerically as soon as it finds a number in both strings being compared? – Clément – 2012-01-21T18:11:07.940use other means (sed, awk, python, perl etc) to extract the number, put it infront of the filename and then use sort ... – akira – 2012-01-22T07:27:07.740
Ok, did it with awk. – Clément – 2012-01-22T23:18:10.577