Deleting lines matching regexp.

  • Thread starter Nikita Synytskyy
  • Start date
N

Nikita Synytskyy

I feel this should be so obvious, but it isn't...

From the command line, I'm trying to delete all lines matching a
particular regexp. I know how to do a substitution:

perl -wpi -e "s/foo/bar/g" filename.ext

Now, how do I delete all lines that contain "foo"?

Nikita.
 
W

Walter Roberson

: From the command line, I'm trying to delete all lines matching a
:particular regexp. I know how to do a substitution:

:perl -wpi -e "s/foo/bar/g" filename.ext

:Now, how do I delete all lines that contain "foo"?

I swear essentially the same question was asked not more than 2 days ago...

perl -wni -e 'print unless /foo/" filename.ext
 
J

J Krugman

In said:
perl -wni -e 'print unless /foo/" filename.ext
^

Minor typo there.

Also, to the OP I would advise to use the variant

perl -i.bak -wne 'print unless /foo/' filename.ext

so that, in case your command-line Perl doesn't attain its customary
brilliance, you will be able to try again.

jill
 
N

Nikita Synytskyy

Walter said:
:Now, how do I delete all lines that contain "foo"?

I swear essentially the same question was asked not more than 2 days ago...

perl -wni -e 'print unless /foo/" filename.ext

I can believe it, too! It's obvious if you know the answer, otherwise
you'll spend a day searching.

Thanks for the speedy reply.

Nikita.
 
G

gnari

Nikita Synytskyy said:
I feel this should be so obvious, but it isn't...

From the command line, I'm trying to delete all lines matching a
particular regexp. I know how to do a substitution:

perl -wpi -e "s/foo/bar/g" filename.ext

use -n instead of -p
Now, how do I delete all lines that contain "foo"?

perl -wni -e "print unless /foo/" filename.ext

the -p is just like -n with implicit print

gnari
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top