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...
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?
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'