Please answer all the questions: **According to the script below: //suppose my m
ID: 3596054 • Letter: P
Question
Please answer all the questions:
**According to the script below:
//suppose my message header's from level looks like this: From your_username@department.css.university.edu TIMESTAMP of when message was receive //how do I get the timestamp portion using pattern matching?
//finally, once the file is created, I will need to auto-reply to the message sender with the following message: "your message was received successfully"
//Attach the newly created file containing their original message
while read label contents ; do
while [ $? -eq 0 -a "$label" == "From" ]; do
while [ "$label $contents" != " " ]; do
case "$label" in
"From")
email=${contents%% *}
sender=${email%@*}
timpestamp=${timestamp pattern matching}
;;
* )
:
;;
esac
read label contents
done
touch _.mesg
read label contents
while [ "$label $contents" != " " ]; do
echo "$label $contents" >> .mesg
read label contents
done
done
done < /var/mail/$USER
Explanation / Answer
You can get the timestamp portion using the below command:
grep -o '[0-2][0-9]:[0-5][0-9]:[0-5][0-9]' sample.txt
Script:
while read label contents ; do
while [ $? -eq 0 -a "$label" == "From" ]; do
while [ "$label $contents" != " " ]; do
case "$label" in
"From")
email=${contents%% *}
sender=${email%@*}
timpestamp=`grep -o '[0-2][0-9]:[0-5][0-9]:[0-5][0-9]' sample.txt`
;;
* )
:
;;
esac
read label contents
done
touch _.mesg
read label contents
while [ "$label $contents" != " " ]; do
echo "$label $contents" >> .mesg
read label contents
done
done
done < sample.txt