Find the answer to your Linux question:
Results 1 to 3 of 3
I am learning to use the grep command, so far so good but it is a little confusing... specially since I don't have a book and my only resouse is ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Feb 2007
    Posts
    2

    grep command line - some confusion


    I am learning to use the grep command, so far so good but it is a little confusing... specially since I don't have a book and my only resouse is some websites. Any one has recommendations for books?

    I am trying to search for 'aaa' or 'aaaa' or 'aaaaa', something with those characteristics... from lets say the /etc directory. I also want to add two lines of context before and after each keyword found.

    I started doing this


    Code:
    [root@localhost ~]# grep x\{3,5\} /var

    But I don't know where to put the spaces and if I am using the right character, I did this with no errors but I am not sure if I am doing it right.


    Code:
    [root@localhost ~]# grep x**\{3,5\**} /var

    Now... what if I want to find multiple words, which is the AND command?

    I learned the OR command [

    Code:
    root@localhost ~]# grep -nr 'gold\|silver'

    What if I want to search for lets say : gold and silver and copper and diamonds and sand
    Is this accepted?

    Code:
    grep -w '\<gold\ silver\copper\ diamonds\>'



    Any clarification will help alot.
    Thank you!

  2. #2
    Linux User
    Join Date
    Aug 2006
    Location
    Croydon, PA
    Posts
    392
    Try doing a man grep
    Hopefully that will give you some ideas.
    Good Luck,
    Ski
    RHCT

  3. #3
    Just Joined!
    Join Date
    Feb 2007
    Posts
    2
    Thanks!
    I will look info about man grep.

  4. $spacer_open
    $spacer_close

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •