Link to home
Start Free TrialLog in
Avatar of Edgar Cole
Edgar ColeFlag for United States of America

asked on

How can I remove lines from a file that match multiple patterns?

I have a file from which I'd like to be able to remove lines that match multiple patterns. For example, I might want to remove all lines containing 'AIX' and '5.3.'
Avatar of omarfarid
omarfarid
Flag of United Arab Emirates image

try

grep -v "AIX*5\.3" filename

or if you mean AIX or 5.3 then try

grep -v "AIX|5\.3" filename
PAT1="AIX"
PAT2="5.3"

awk -v P1=$PAT1 -v P2=$PAT2 '{if ($0~P1&&$0~P2) next; else print}' inputfileoutputfile

wmp
Do you want to remove lines which contain both  'AIX' and '5.3.'
or do you want to remove lines containing  'AIX'  and lines containing '5.3.' ?
If the latter

cat > patterns <<END
AIX
5.3.
END
grep -vFf patterns inputfile > outputfile
Avatar of Edgar Cole

ASKER

I'm sorry. Yes, the lines must contain both patterns.
ASKER CERTIFIED SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
did you try the grep command given?