I have log file. I want extract email list from specific lines. Sample log file:
05:06:48,311 INFO http-nio-8080-exec-81 controller.IndexController:221 - Attempt to login: [[email protected]]. Headers: ["content-length": "52", ...]
15:06:48,311 INFO http-nio-8080-exec-81 controller.IndexController:221 - Attempt to login: [[email protected]]. Headers: ["content-length": "52", ...]
09:40:21,187 INFO http-nio-8080-exec-31 security.AuthAuthenticationProvider:81 - User: [16167]. Wrong code. Telegram: [0]. Google: [0]
My script:
cat file.log | sed -r 's/.*Attempt to login: \[(.*)\]\..*/\1/' | sort | uniq > file.log.filtered.txt
I get file.log.filtered.txt:
09:40:21,187 INFO http-nio-8080-exec-31 security.AuthAuthenticationProvider:81 - User: [16167]. Wrong code. Telegram: [0]. Google: [0]
[email protected]
Why I have line with "AuthAuthenticationProvider" in filtered file?
Because you are running your
sed
command only on lines which contains :Attempt to login
so other lines will stay untouched.You can change your code like this:
so it exclude the other lines first, then extracts email addresses.
or this one:
or even this one:
Or just use grep:
Regex for last command form here