Mar 12, 2007 #1 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?
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?
Mar 12, 2007 #2 ishnid Programmer Joined Aug 29, 2003 Messages 1,422 Location IE 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 Upvote 0 Downvote
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