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 occurred in the input.

Brought to you by Warp, a free terminal reimagined to work like a modern app.
file_name

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