Grep magic
I have this wonder in my logs:
FROM='Mr. Void <[email protected]>'|||ENV_FROM='<[email protected]>'
And this is my parser:
grep -oP "(?<=FROM=\').*?(?=\')"
It does work by bringing me both FROM and ENV_FROM. This is bad. I want EXACT match. Is it possible with lookbehind and lookahead?
Comments
Is the "FROM" that you're after always at the start of a new line? If so, just change it to:
grep -oP "(?<=^FROM=\').*?(?=\')"
and it won't pick up the "ENV_FROM".
Humble janitor of LES
Proud papa of YABS
Does:
grep -oP "(?<=\bFROM=\').*?(?=\')"
solve it for you? (I added\b
beforeFROM
to signify word boundary and it worked as I think how you'd like it to work - i.e only match FROM and not ENV_FROM).Here's a sample test case from me:
(the first one is with a capital - not what you want, and the second one is with a lower case - I think what you want).
gives me:
And what I think you want is:
gives me:
Yes, \b did the trick. Thank you for your time and effort. Greatly appreciated.