Sort a file by line length

Sorts a text file by line length (including spaces). The `-s` flag indicates that any lines that are the same length are kept in the relative order that they ocurred in the input.

file_name

Command
Copy
cat file_name | awk '{ print length, $0 }' | sort -n -s | cut -d" " -f2-
Tags