Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Very basic grep question

Options
  • 20-12-2009 4:40pm
    #1
    Posts: 5,589 ✭✭✭


    Say I have a log file, for example lets say its the auth.log

    Is there a way to use to grep to pull out the lines that had 'accepted' and 'root' in it? So I can see who logged in and then who invoked root.

    Since these are on different lines, I can't pipe the second grep, so I would be looking to grep [acc OR root]. Is that possible?


Comments

  • Registered Users Posts: 85 ✭✭StiLL-TrAiNinG


    egrep "root|acc" is what you're looking for I believe.


  • Posts: 5,589 ✭✭✭ [Deleted User]


    Thanks, what is the syntax as the following code isn't working
    cat /var/log/auth.log | egrep acc|root > /some/where/else
    


  • Registered Users Posts: 85 ✭✭StiLL-TrAiNinG


    Thanks, what is the syntax as the following code isn't working
    cat /var/log/auth.log | egrep acc|root > /some/where/else
    

    Ah, the acc|root needs to be quoted, otherwise it'll think that it's just another pipe character.

    Also for grep, you don't need to cat something first.

    This should be it:
    egrep "acc|root" /var/log/auth.log > /some/where/else
    


  • Posts: 5,589 ✭✭✭ [Deleted User]


    Thanks! That works perfectly


Advertisement