Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Very basic grep question

  • 20-12-2009 04:40PM
    #1
    Posts: 6,176 ✭✭✭


    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, Registered Users 2 Posts: 85 ✭✭StiLL-TrAiNinG


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


  • Posts: 6,176 ✭✭✭ [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, Registered Users 2 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: 6,176 ✭✭✭ [Deleted User]


    Thanks! That works perfectly


Advertisement