Created
May 11, 2015 13:00
-
-
Save gautiermichelin/358a819557cb3b88dac6 to your computer and use it in GitHub Desktop.
Eml2csv : shell script to extract To/From/Subject/Date from eml files inside a folder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for posting this Gautier, was exactly what I was looking for! 😃