in reply to How can I find and delete a line from a file?

Put simply, you'll have to read in the file, process it, and then save it back out.

my( $filename, $arg1, $arg2 ) = @ARGV; open IN, '<', $filename or die; my @contents = <IN>; close IN; @contents = grep !/^$arg1,$arg2,/, @contents; open OUT, '>', $filename or die; print OUT @contents; close OUT;

This will force the first and second field in the file to match exactly the first and second arguments that you pass in.

Replies are listed 'Best First'.
Re: Answer: How can I find and remove a line from a file.
by mpd (Monk) on Aug 30, 2003 at 05:20 UTC
    If you know the exact line number you want to "delete," try this one-liner:
    perl -ni -e "print unless $. == $linenum" <filename>