Q:

How can I remove empty lines in every file of a directory?

How can I remove empty /blank lines in every txt file of a directory (ideally subdirectories too)?
find . -name '*.txt' -exec ex '+%s/\ / /g' -cwq {} \;

Above code is pulling list of files correctly but i am not sure what regular expression to pass to remove blank lines.

A:

With GNU find and GNU sed:
find . -name '*.txt' -exec sed -ri '/^\s*$/d' {} \;

