Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 79
  • Last Modified:

filter a list of processes without using grep -v

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
lolaferrari
Asked:
lolaferrari
  • 2
  • 2
  • 2
2 Solutions
 
serialbandCommented:
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
 
tel2Commented:
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
 
lolaferrariAuthor Commented:
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
New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

 
tel2Commented:
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
 
lolaferrariAuthor Commented:
Fantastic help! thank you
0
 
serialbandCommented:
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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now