Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

why this deleting-a-line one-liner not working

Status
Not open for further replies.

sedawk

Programmer
Joined
Feb 5, 2002
Messages
247
Location
US
Hi,

I try to delete a line a file using this one-liner:

perl -p -e 'next if /delete/i' < test.txt | tee out.txt

test.txt has this format:
line 1
delete line
Line DELETE
line2

out.txt should have this format:
line1
line2

But it doesn't work. why?

 
Using the -p switch causes the following to be placed around your code:
Code:
LINE:
while (<>) {
  ...             # your program goes here
} continue {
   print or die "-p destination: $!\n";
}
Calling "next" doesn't stop the "continue" block being executed, so the line will be printed in any event.

I'd change it to this:
Code:
perl -ne 'print unless /delete/i' test.txt | tee out.txt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top