sort filenames based on first-line of file
August 1st, 2011 by Lawrence David
i’ve got a bunch of files with one line — a number — and i’d like to sort those filenames on the command line based on that number.
to that in one line of shell code:
for i in `ls *.*`; do echo “`head -n1 $i` $i” ; done | sort -n