I need to cut the text that comes after -m which is "this is a test" and place it in front of the line with echo statment.
I think Awk will not work as -m will not be in the same column everytime.
I don't see how the variability of the position of "-m" matters. Awk is just performing the translation on any line beginning with "/usr/local/bin/gmail".
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.comlmn@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.comlmn@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