xyz
xyz

Reputation: 8917

How to delete lines matching a certain pattern in Perl?

I'd like to do something similar to sed in Perl, namely be able to delete lines matching a certain pattern.

Given this input:

abcd
edfd
abcd
derder
abcd
erre

I want to remove the lines containing bc. How can I do this?

Upvotes: 5

Views: 9845

Answers (2)

xyz
xyz

Reputation: 8917

I had to use double quotes on Windows:

perl -ne "print unless /bc/" file

Upvotes: 8

Dave Cross
Dave Cross

Reputation: 69244

This is a FAQ.

How do I change, delete, or insert a line in a file, or append to the beginning of a file?

If you're programming in Perl then it's well worth taking a couple of hours to familiarise yourself with the FAQ.

Upvotes: 3

Related Questions