Remove empty lines from file

Joshua Root jmr at macports.org
Sat Nov 19 01:23:09 PST 2011


On 2011-11-19 09:21 , Bradley Giesbrecht wrote:
> I have tried 1 to 5 escapes to replace a newline and/or carriage returns with nothing.
> 
> reinplace "s|\n||g" file_path
> also
> reinplace -E "s|\n||g" file_path
> 
> Looking at other ports I see 1, 2 and 3 escapes inside double quotes.

The issue here is that sed operates on a line at a time, which doesn't
include the terminating newline. Ryan's reply shows how to match a blank
line and delete the entire line.

Regarding escaping, if you want to avoid having to protect things from
the Tcl parser you can wrap the string in braces.

- Josh


More information about the macports-dev mailing list