How to use GREP to get the results I want?

Posted on 2006-05-31
Last Modified: 2013-12-16

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 "" and ""?


Question by:su-n
    LVL 43

    Assisted Solution

    grep searchterm /path/* | grep -v '' | grep -v '' > 01
    LVL 3

    Accepted Solution

    Ravenpl is correct, but here is another way:

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

    Also, you might want to try something like this:

    grep searchterm /path/* 2>/dev/null | grep -v -e '' -e '' > 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
    LVL 1

    Author Comment

    Thanks alot for your help!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    Title # Comments Views Activity
    disks not visible after OS upgrade linux 5 78
    Linux SSH Error 9 52
    Filename as video title in playback 1 51
    Zenoss 2 40
    Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
    Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
    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…
    Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now