Bash Perl "And" Operator

with a output:

apple text1
peach text2
banana text3
melon text4

For delete rows that begin with "apple" or "banana" i put:

perl -pe 's/^apple.*\n|^banana.*\n//g'

And output is correct:

peach text2
melon text4

But I want delete also an eventual "papaya" or "mango" for example. For achieve this I apply the De Morgan law:

perl -pe 's/^(?!peach).*\n&^(?!melon).*\n//g'

But nothing is deleted because while "|" stands for "or", "&" does not work.
What symbol stands for "and" in bash perl command?

2

1 Answer

You can concatenate the two matching expressions like this:

perl -pe 's/^(?!peach)(?!melon).*\n//g'

or you can use the "or" operator like this:

perl -pe 's/^(?!(peach|melon)).*\n//g'
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

James H. Sterling

James H. Sterling

Environmental Science & Climate Journalist

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.

Share this article
Twitter Facebook Pinterest