[plug] A question about using sed - removing blank lines

Arie Hol arie99 at ozemail.com.au
Fri Apr 25 17:27:22 WST 2008



On 25 Apr 2008 at 17:08, Nick Bannon wrote:

> On Fri, Apr 25, 2008 at 03:29:00PM +0800, Arie Hol wrote:
> > I have tried using the following command to remove the blank lines :
> > 
> > 	sed -ie "s/^\s*$//i" *.html
> [...]
> 
> First - sed doesn't understand all of the extended Perl-style regular
> expressions. Use [	] instead of \s , where the brackets contain a space
> and a true tab character, ASCII 32 and ASCII 9. You can type the tab
> character into a shell or vi with <CTRL-V><CTRL-I>.
> 
> Second - that will remove the space characters, but not the actual 
line,
> you'll be left with blank lines that /^$/ would match. Try this: 
> 
>  sed -ni.bak '/[^ 	]/p' *.html
> 

Hello Nick,

Thanks for your reply

I suppose I should have mentioned that I am using GNU Utils for Windows - 
:-)

I cannot reboot into Linux due to a large download currently taking place 
in the background - so I thought I would try and use sed to do the job.

Live and learn - learn and live.	:-) 

I have tried all of the following commands :

sed -ie 's/^\s*$//i' *.html

sed -ie 's/^ *$//i' *.html

sed -ie 's/^$//i' *.html

sed -ie 's/^$//d' *.html

sed -ie 's/^\n$//i' *.html

sed -ie 's/[^\n$|^\t*$|^\n*$|^\s*$]//i' *.html 

sed -ie 's/^[[:space:]]*$//i' *.html 

sed -ie "s/^[[:blank:]]*$//i" *.html

sed -ie 's/^[:space:]*$//i' *.html 

sed -ie "s/^[:blank:]*$//i" *.html

All the above commands gave the same result :

1 - no error messages 
2 - blank lines still persist 

The command you suggested also returned the same results

sed -ni.bak '/[^ 	]/p' *.html

I also tried :

sed -ni.bak '/[^ 	$]/p' *.html

With same results

I will have to wait until the download has finished and then I will 
reboot into linux and try sed on Linux or write a Perl script to do the 
job.

Regards Arie
------------------------------------------------------------------
 For the concert of life, nobody has a program.
------------------------------------------------------------------



More information about the plug mailing list