> -----Original Message----- > From: Bkwyrm [mailto:[EMAIL PROTECTED]] > Sent: Thursday, November 29, 2001 12:22 PM > To: [EMAIL PROTECTED] > Subject: [[EMAIL PROTECTED]: RE: Elegant way to > find/remove > line from text file] > > > Tested these in order to learn how they work, and the first > one simply deleted the entire contents my test file which was > peppered with foo on multiple (but not all) lines.... > > ----- Forwarded message from Bob Showalter > <[EMAIL PROTECTED]> ----- > > Second, the canonical one-liner to delete lines from a file is: > > perl -ni -e 'next unless /foo/' myfile.txt > > This deletes all lines matching /foo/. To only delete the first > line matching /foo/, you need something like this: > > perl -ni -e 'next unless /foo/ && !$x++' myfile.txt > > ----- End forwarded message -----
OK, I'm having a bad day. I think I'll go tak a nap. Those should be "print unless", not "next unless": perl -ni -e 'print unless /foo/' myfile.txt perl -ni -e 'print unless /foo/ && !$x++' myfile.txt Leave off the -i for testing. Thanks for catching my screw-up. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]