#!/bin/bash
FILES=*.eml
TARGET=./Contacts.csv

SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
echo "FullName\Email" >> $TARGET
for f in $FILES
do
  echo "Processing $f file..."
  # take action on each file. $f store current file name
  FN=$(grep "^FN" < $f | sed -e "s/FN://g")
  EML=$(grep "^EMAIL;TYPE=WORK:" < $f | sed -e "s/EMAIL;TYPE=WORK://g")
  echo -e "${FN//[$'\t\r\n']}\t${EML//[$'\t\r\n']}" >> $TARGET
done
IFS=$SAVEIFS