Edgar Cole
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.'
PAT1="AIX"
PAT2="5.3"
awk -v P1=$PAT1 -v P2=$PAT2 '{if ($0~P1&&$0~P2) next; else print}' inputfile > outputfile
wmp
PAT2="5.3"
awk -v P1=$PAT1 -v P2=$PAT2 '{if ($0~P1&&$0~P2) next; else print}' inputfile > outputfile
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.' ?
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
cat > patterns <<END
AIX
5.3.
END
grep -vFf patterns inputfile > outputfile
ASKER
I'm sorry. Yes, the lines must contain both patterns.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
did you try the grep command given?
grep -v "AIX*5\.3" filename
or if you mean AIX or 5.3 then try
grep -v "AIX|5\.3" filename