Thank you Glenn, Matrix and Aju for the help.
Seems like I am moving forward. Below is Input files, Code and Output on screen.
Now, how would I replace the current line with the edited line (temp1 in my code)?
Thanks again everyone for the input. I'm learning new things here.
--------------------------
Input file 1:
this is line 1 of test file
this is line 2 of test file
/usr/local/bin/gmail -s "Subject line"
abc@yahoo.com lmn@yahoo.com -m " Message for file 1 " -f
xyz@yahoo.com -a /home/kcc1hxj/testfile1.txt
this is line 4 of test file
Input file 2:
this is line 1 of test file
this is line 2 of test file
/usr/local/bin/gmail -s "Subject line" -a /home/kcc1hxj/testfile2.txt
abc@yahoo.com lmn@yahoo.com -m " Message for file 1 " -f
xyz@yahoo.com
this is line 4 of test file
Code:
#!/bin/ksh
for file in /home/kcc1hxj/projects/removemail/scripts/*
do
temp1=`grep ^.*/usr/local/bin/gmail $file | sed 's/\(.*-m \)\(".*"\)\( .*\)/echo \"\2\" | \1\3/' | sed 's/""/"/g'`
echo $temp1
done
Output on screen:
echo " Message for file 1 " | /usr/local/bin/gmail -s "Subject line"
abc@yahoo.com lmn@yahoo.com -m -f
xyz@yahoo.com -a /home/kcc1hxj/testfile1.txt
echo " Message for file 1 " | /usr/local/bin/gmail -s "Subject line" -a /home/kcc1hxj/testfile2.txt
abc@yahoo.com lmn@yahoo.com -m -f
xyz@yahoo.com