?
Solved

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

Posted on 2012-09-04
7
Medium Priority
?
431 Views
Last Modified: 2012-09-14
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.'
0
Comment
Question by:babyb00mer
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 40

Expert Comment

by:omarfarid
ID: 38365152
try

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

or if you mean AIX or 5.3 then try

grep -v "AIX|5\.3" filename
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 38365167
PAT1="AIX"
PAT2="5.3"

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

wmp
0
 
LVL 85

Expert Comment

by:ozo
ID: 38365223
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.' ?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 85

Expert Comment

by:ozo
ID: 38365247
If the latter

cat > patterns <<END
AIX
5.3.
END
grep -vFf patterns inputfile > outputfile
0
 

Author Comment

by:babyb00mer
ID: 38365363
I'm sorry. Yes, the lines must contain both patterns.
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 1600 total points
ID: 38365406
So consider trying my awk solution!
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 38366433
did you try the grep command given?
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses
Course of the Month16 days, 10 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question