[Ilugc] Removing Blank lines and same file has to be affected

  • From: gopal@xxxxxxxxxxxxxxxxx (Gopalarathnam Venkatesan)
  • Date: Wed Aug 16 17:51:35 2006

Girish Venkatachalam wrote:

sed -n -i '/^$/!p' file1.txt
Good. In this particular this gives exactly what you
want.

But in general for generic in place editing and text
munching the "perl -pi" route seems to be the only
way
out.

Otherwise it is impossible to do in place editing.

Sorry I was wrong. The -i flag to sed clearly implies
in place editing.


Yes, but the "-i" option in sed is non standard and is not available on 
all operating systems.

Either Perl works here, or ed(1) can be used.

shell> ed file1.txt
1,$s/^$/d
w
q

If this needs to be written as part of a program, then the following can 
be used:

ed file1.txt <<!
1,$s/^$/d
w
q
!

-- 
Gopalarathnam Venkatesan

http://gopalarathnam.com/

Other related posts: