Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

filter a list of processes without using grep -v

Posted on 2016-08-09
6
Medium Priority
?
77 Views
Last Modified: 2016-08-11
I have a list of processes running on my server pasted out into a file and I want to filter out maybe 60 processes that i have in another list. Is there a better way of doing this than using grep -v ?
0
Comment
Question by:lolaferrari
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 30

Accepted Solution

by:
serialband earned 1000 total points
ID: 41749204
Are you having trouble with the syntax?

grep -Ev 'Term1|Term2|Term3|Term4' filename.txt
egrep -v '(Term1|Term2|Term3|Term4)' filename.txt


grep -v -f exclude_list.txt filename.txt
1
 
LVL 12

Assisted Solution

by:tel2
tel2 earned 1000 total points
ID: 41749640
Hi serialband,

> "egrep -v '(Term1|Term2|Term3|Term4)' filename.txt"
What is the purpose of the "(" & ")" in this example?

Would you agree that this would give the same result:
    egrep -v 'Term1|Term2|Term3|Term4' filename.txt

I would have thought that the () would only be useful if you also had something outside of them, e.g.:
    egrep -v 'The (Term1|Term2|Term3|Term4) is' filename.txt

tel2
0
 

Author Comment

by:lolaferrari
ID: 41750002
I just thought there might have been a better way to filter things out than using egrep -v ('...') You see I might have as many as 40 or 50 items that I want to filter out and I just wondered if there was another way to do it.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 12

Expert Comment

by:tel2
ID: 41750152
Hi lolaferrari,

serialband has given you 3 options.  What is wrong with the 3rd one of them?  You can put your 40 or 50 (or as many as you like) items in the exclude_list.txt file (or whatever filename you what to use).
0
 

Author Comment

by:lolaferrari
ID: 41750584
Fantastic help! thank you
0
 
LVL 30

Expert Comment

by:serialband
ID: 41752224
Ok, strange.  I though I responded to you @tel2.  In fact, I remember doing it twice, but I still don't see my response.


It's as you say.  I gave examples to help with the syntax, since I wasn't sure what @lolaferrari needed.

@lolaferrari
The 3rd option is best with a file with 40 or 50 items.  I can't think of anything that would improve on that.  The grep command placese everything into one grep process.  Anything else would spawn additional processes and slow it down more.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
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 recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

721 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