[plug] Need help with sed

Carl Gherardi carl.gherardi at gmail.com
Mon Aug 3 13:09:46 WST 2009


On Mon, Aug 3, 2009 at 1:07 PM, Arie Hol<arie99 at ozemail.com.au> wrote:
>
> I am currently processing a large number of files using sed;
>
> I am running sed as a series of commands from a shell script
>
> The problem I have is :
>
> sed is leaving "blank" lines where it removes the 'target text' - many of
> these blank lines contain tabs and spaces (whitespace).
>

I have a useful file on my drive called sed1liners.

Latest version of this file is usually at:
   http://sed.sourceforge.net/sed1line.txt

 # delete BOTH leading and trailing whitespace from each line
 sed 's/^[ \t]*//;s/[ \t]*$//'

> I can remove some of the  whitespace but I still end up with blank lines.

 # delete ALL blank lines from a file (same as "grep '.' ")
 sed '/^$/d'                           # method 1
 sed '/./!d'                           # method 2

> Is there a sed command I can use to remove any/all lines which appear to
> only have whitespace or are just blank lines?

Combination of the above should do the trick.

Carl G



More information about the plug mailing list