Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    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

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

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

    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?

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

    Any clarification will help alot.
    Thank you!

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

  3. #3
    I will look info about man grep.

  4. $spacer_open

Posting Permissions

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