in reply to (code) One-liner removes whitespace-only lines from text file
This snippet removes all non-empty lines containing only whitespace, but I don't think that's particularly intuitive behaviour. If I want to remove all "blank" lines from a file, I probably want:
perl -i.bak -ne 'print if /\S/' file.txt
and if I want to get rid of all the lines with "useless" whitespace, I probably want to collapse them to empty lines:
perl -i.bak -ne 's/^\s+$//;print' file.txt
Update: Changed first one-liner to Ovid's for readability.
--
|
|---|