Basically what I want to do is parse the lines in the file and return the usernames. Usernames are always surrounded by <and>, so I want to use a regular expression to match eveything before (and including) and everything after (including)>, and then invert my match. I understand that grep -vE should do this.
My script looks a bit before this:
#!/bin/bash
while read line; do
echo $line | grep -vE '(.*<)|(>.*)'
done < test_log
And test_log consists of the following:
Mar 1 09:28:08 (IP redacted) dovecot: pop3-login: Login: user=<emcjannet>, method=PLAIN, rip=(IP redacted), lip=(IP redacted)
Mar 1 09:27:53 (IP redacted) dovecot: pop3-login: Login: user=<dprotzak>, method=PLAIN, rip=(IP redacted), lip=(IP redacted)
Mar 1 09:28:28 (IP redacted) dovecot: imap-login: Login: user=<gconnie>, method=PLAIN, rip=(IP redacted), lip=(IP redacted), TLS
Mar 1 09:27:25 (IP redacted) dovecot: imap-login: Login: user=<gconnie>, method=PLAIN, rip=(IP redacted), lip=(IP redacted), TLS
However, when running my script, nothing returns, even though when I test the regex in something like regexpal with a backward match, it does exactly what I want. What am I doing wrong?
source
share