Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Eml2csv : shell script to extract To/From/Subject/Date from eml files inside a folder
#!/bin/bash
FILES=*.eml
TARGET=./emails.csv
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
echo "To\tFrom\tSubj\tDate" >> $TARGET
for f in $FILES
do
echo "Processing $f file..."
# take action on each file. $f store current file name
EMLTO=$(grep "^To" < $f | sed -e "s/To://g")
EMLFROM=$(grep "^From" < $f | sed -e "s/From://g")
EMLSUBJ=$(grep "^Subject" < $f | sed -e "s/Subject://g")
EMLDATE=$(grep "^Date" < $f | sed -e "s/Date://g")
echo -e "${EMLTO//[$'\t\r\n']}\t${EMLFROM//[$'\t\r\n']}\t${EMLSUBJ//[$'\t\r\n']}\t${EMLDATE//[$'\t\r\n']}" >> $TARGET
done
IFS=$SAVEIFS
@brendanmullan

This comment has been minimized.

Copy link

brendanmullan commented Feb 25, 2018

Thanks for posting this Gautier, was exactly what I was looking for! 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.