Search code examples
pythonemailawksedboundary

How to get primary boundary value from EML file


I'm trying to get primary boundary value from EML file using sed

sed -n -e '/boundary=\"/,/\"/p; /\"/q' file.eml

but what I'm getting is a whole line

boundary="B06E1103658.1514636705/test-box.local"

instead of a value only

B06E1103658.1514636705/test-box.local

What I have done wrong? awk solution is welcome as well (or Python).


Solution

  • Probably simpler with grep lookbehind

    grep -oP '(?<=boundary=")[^/]+'
    

    will give you B06E1103658.1514636705, whereas

    grep -oP '(?<=boundary=")[^"]+'
    

    gives B06E1103658.1514636705/test-box.local

    not sure which one you want?