I have a CSV file that looks like this
AS2345,ASDF1232, Mr. Plain Example, 110 Binary ave.,Atlantis,RI,12345,(999)123-5555,1.56 AS2345,ASDF1232, Mrs. Plain Exampl
The length()
function does include spaces. I would make just minor adjustments to your pipeline (including avoiding UUOC).
awk '{ printf "%d:%s\n", length($0), $0;}' "$@" | sort -n | sed 's/^[0-9]*://'
The sed
command directly removes the digits and colon added by the awk
command. Alternatively, keeping your formatting from awk
:
awk '{ print length($0), $0;}' "$@" | sort -n | sed 's/^[0-9]* //'