Solved

filter a list of processes without using grep -v

Posted on 2016-08-09
6
61 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
  • 2
  • 2
  • 2
6 Comments
 
LVL 29

Accepted Solution

by:
serialband earned 250 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 250 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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 29

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Utilizing an array to gracefully append to a list of EmailAddresses
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…

828 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