Solved

filter a list of processes without using grep -v

Posted on 2016-08-09
6
70 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 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
RoboCopy to Changing External Drives 2 70
AWS CLI - Instances, Volumes & Tagging 2 154
Shell script issue 4 66
Use awk or sed to manipulate Columns in a File 12 45
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 …
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…

751 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