Purchase Linux CDs / DVDs / Flash Drives at OSDisc.com

Welcome to Our Community

While Linux.org has been around for a while, we recently changed management and had to purge most of the content (including users). If you signed up before April 23rd, 2017 please sign up again. Thanks!

  1. More ways to get the info! - we shoot all of our new original content out as well as random messages on Twitter and our newsletter!. Twitter | Newsletter
    Dismiss Notice

Exclude unwanted string from Linux grep

Discussion in 'Command Line' started by Gabriel9999, Apr 3, 2019.

  1. Gabriel9999

    Gabriel9999 New Member

    Joined:
    Mar 12, 2019
    Messages:
    15
    Likes Received:
    0
    I have a configuration file which is a simple text. I want to list some configuration line but except some sitring. How can I use Linux grep to exclude and search for given strings? Thanks in advance for your help!


    (Log in to hide this advertisement)

     
  2. wizardfromoz

    wizardfromoz Super Moderator
    Staff Member Gold Supporter

    Joined:
    Apr 30, 2017
    Messages:
    2,839
    Likes Received:
    2,280
    Moving this to Command Line Gabriel

    Good luck

    Wizard
     
  3. kenJackson

    kenJackson Member

    Joined:
    Mar 11, 2019
    Messages:
    54
    Likes Received:
    43
    Use grep -v
    Code:
    $ echo -e 'abcd\nefgh'
    abcd
    efgh
    $ echo -e 'abcd\nefgh' | grep -v bc
    efgh
     
    JasKinasis likes this.
  4. samuel tarcin

    samuel tarcin New Member

    Joined:
    Mar 6, 2019
    Messages:
    7
    Likes Received:
    1
    There are different ways to exclude and grep given a text file or input stream. I generally prefer the most basic one where use two grep where the first one is for exclude with -v option and pipe to second one where I grep for my string. grep -v 'able' config.txt | grep 'system' For more information look https://www.poftut.com/introduction-to-linux-grep-command-with-examples/
     
  5. Gabriel9999

    Gabriel9999 New Member

    Joined:
    Mar 12, 2019
    Messages:
    15
    Likes Received:
    0
    Thanks for your offer to help
     

Share This Page