> Justin To wrote:
> Hi, how do I delete a line in a file and remove the empty space
> afterward?
> 
> Thanks!

Some additional in-place file editing options on Unix:

/bin/ed -s file.txt <<< $'/b/d\nw'   # delete first line containing "b"

/bin/ed -s file.txt <<< $'g/b/d\nw'   # delete all lines containing "b"
/usr/bin/sed -i "" -e '/b/d' file.txt

/bin/ed -s file.txt <<< $'2,2d\nw'    # delete second line
/usr/bin/sed -i "" -e '2,2d' file.txt

More on the ed text editor here:
http://bash-hackers.org/wiki/doku.php?id=howto:edit-ed


Using Ruby from the command line:

ruby -p -i -e 'm ||= 0; m == 1 ? $_ : $_.sub!(/^.*2.*$/m, "") || $_; m = 
1 unless $~.nil?' file.txt
ruby -p -i -e '$_.sub!(/^.*b.*$/m, "")' file.txt
ruby -p -i -e '$_.sub!(/^.*$/m, "") if $. == 2' file.txt

For more information on selective deletion of certain lines see:
http://www.fepus.net/ruby1line.txt


Cheers,

j.k.

-- 
Posted via http://www.ruby-forum.com/.