cat test.txt | sed -e's/\(.*\) \(.*\)/\2,\1/g' | sort #### $ sort +1 -2 +0 -1 output.txt