?
Solved

How to use GREP to get the results I want?

Posted on 2006-05-31
3
Medium Priority
?
338 Views
Last Modified: 2013-12-16
Hi,

I have to search for an expression in several log's, but the way I can use grep, the resulting file too large (few 10's of thousands of rows). Therefor there should be an exclude expression to shorten the result.

What I've done:

grep searchterm /path/* > 01

and I do get a file of 40MB.

In file 01 are terms/expression I want to exclude in the result.

How do I use grep to get all rows with "searchterm", but without "192.168.0.1" and "192.168.0.2"?


Thanks,
Sven

0
Comment
Question by:su-n
3 Comments
 
LVL 43

Assisted Solution

by:ravenpl
ravenpl earned 1000 total points
ID: 16800223
grep searchterm /path/* | grep -v '192.168.0.1' | grep -v '192.168.0.2' > 01
0
 
LVL 3

Accepted Solution

by:
bryanlloydharris earned 1000 total points
ID: 16802227
Ravenpl is correct, but here is another way:

grep searchterm /path/* | grep -v -e '192.168.0.1' -e '192.168.0.2' > 01

Also, you might want to try something like this:

grep searchterm /path/* 2>/dev/null | grep -v -e '192.168.0.1' -e '192.168.0.2' > 01

By putting 2>/dev/null, you are not regarding any error messages.  This is good to do if you get some messages which say:

/some/path: is a directory
0
 
LVL 1

Author Comment

by:su-n
ID: 16805752
Thanks alot for your help!
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

How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
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…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month17 days, 11 hours left to enroll

830 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