Tuesday, 28 July 2009

Quick one liner: Remove empty lines from files

This quick bash and perl one liner will remove any empty lines from all the files in the current directory.

for f in *;do perl -i -ne 'print unless /^$/' ${f};done
It will not remove lines that contain only white space however. For that you would need:


for f in *;do perl -i -ne 'print if /\S/' ${f};done

No comments:

Post a Comment