Celeb Glow
general | March 26, 2026

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

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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