I am trying to extract values from email header, as the Message ID
The grep do not properly use the previous variable...
Here is my code:
for email in $1/*.eml
do
MSGID=$(cat ${email} | grep -i 'Message-ID:' |awk '{print $2}')
M=$(echo "\""${MSGID}"\"")
SRV="/var/log/maillog"
echo "${M}"
VER=$(grep -i ${M} ${SRV} | tail -n 1)
echo ${VER}
done
I am trying to re-encapsule the initial variable MSGID with M variable; Unfortunately I still could not figure this out.
Initial value (input) looks like this:
Message-ID: <COMPUTER123DDF38c28d5e776e4fbdb82e2e92bd9a4373@computer123ddf>
The MSGID keep only the string as:
<COMPUTER123DDF38c28d5e776e4fbdb82e2e92bd9a4373@computer123ddf>
Then I would like to use this string against a file using grep. Unfortunately the VER command does not trigger anything.
I thought that adding "\""${MSGID}"\"" would/should have keep the initial string untouched.
awkmay handle it in a way straight-forward way.MSGID=$awk '/^Message-ID:/ {print $2}' file)would be faster. Also, noteSRVcan be declared outside theforloop, since it is a fixed value.