I'm looking to display just the email address in the /var/log/secure file. The email goes into a variable, so just grepping for lines won't work.
I know how to string together sed commands, but is there a cleaner way?
I could even scrap the idea altogether, if there is a cleaner way to get ssh key comment emails. I'm looking to find out which email comment, on the clients ssh key, was used to login. So far I have been using something like this..
ssh root@localhost "sleep 1 ; tail -1 /var/log/secure | ..."
I hope there is a better way, or at least a clean way to display just the email.
Why doesn't grep work out for you? It has the
-o
parameter to get only the match. So something likegrep -o " .+@.+ " /var/log/secure
should work. Only work out the expression to just match the email address.As @Matteo mentioned, I've never seen the public key informations in
/var/log/secure
but if you want to display only email address from a text file, you can useegrep
(for extended regex) with-o
option, something like this:or you must escape the plus if you use
grep
:You can also do it with
sed
: