user2334436 user2334436 - 3 years ago 178
Linux Question

remove all empty lines from text files while keeping format

I have multiple notepad text files which contains one empty line (the last line of each file). I want to delete the empty line form all files. I tried different grep and awk lines but they didn't work plus they messed up the file format; all text are shown on one line instead of separate line. i also tried with notepad++ regex to find

^\s*$
and replace it with nothing, but it also didn't work.

Current text file looks like this:

apples
oranges
peaches
[empty line]


The output should be

apples
oranges
peaches

Answer Source
  • Ctrl+H
  • Find what: \R^$
  • Replace with: LEAVE EMPTY
  • check Wrap around
  • check Regular expression
  • Replace all

Explanation:

\R      : any kind of linebreak
^       : begining of line
$       : end of line

Result for given example:

apples
oranges
peaches
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download