find a string in a file and add some text after that file

Hi
Could you please help me out by solving teh below problem ?
I have a file with as below
source1|target1|yes
source2|target2|no

source1 is file in which i have to place some code under the <head> tag in it.
What code i have to place in source1 is something like this "abcd.....<target1> ...xyz"
But i have to do this replacment only is the third string in the above file "source1|target1|yes" is "yes"
if is no, i shouldn't replace the code.

Could anyone help to resolve this problem ?

Thanks in Advance,
Tasha

Hi Tasha_t,

You can do somethng lik this :

 
cat gre.txt
 
source1|target1|yes
source2|target2|no

for i in `cat "gre.txt" | awk -F"|" '{if ($3=="yes") print $1}' `
do
sed '
/<HEAD>/ a\
Add the text you want
' $i >> save

done

#!/bin/ksh

while IFS='|' read file tag yn
do
   if [ "${yn}" = 'yes' ]; then
      printf "/<%s>/ a\nAdd whatever you want\n.\nwq!\n" "${tag}" | ex - "${file}"
  fi
done < myFile

Sorry, both of them didn't work...
below is the script i wrote which is workign fine till breakign the code
********************
for i in `cat redirect_list`
do
source=`echo "$i" | cut -d '|' -f1`
target=`echo "$i" | cut -d '|' -f2`
move=`echo "$i" | cut -d '|' -f3`
if [ $move = "YES" ] ; then
sed -i 's/\<head\>/..................../g' /export/home/chandu/copies/"$source" ### this is the main line where i have to change to get the actual code working ..
fi
done
**************
Please let me know how i can add text ...

Tasha_T,

FYI , The code tht i hav posted working properly.

Below is the complte info :

 
PANYAM/TESTBOX>cat gre.txt
source1|target1|yes
source2|target2|no
PANYAM/TESTBOX>cat source1
Before Head
<HEAD>
## Text to be added
</HEAD>

<BODY>
dskls
</BODY>

PANYAM/TESTBOX>cat b
for i in `cat "gre.txt" | awk -F"|" '{if ($3=="yes") print $1}' `
do
sed '
/<HEAD>/ a\
Add the text you want
' $i >> op_save
done
PANYAM/TESTBOX>cat op_save
Before Head
<HEAD>
Add the text you want
## Text to be added
</HEAD>

<BODY>
dskls
</BODY>

You hav to note that sed will not edit the text "inline" .You hav to save the file once edited.

ok - misread the original requirements - sorry 'bout that.

Given 'source1':

Before Head
<head>
## Text to be added
</head>

<BODY>
dskls
</BODY>

and myFile:

source1|target1|yes
source2|target2|no

.... and tasha.sh:

#!/bin/ksh

while IFS='|' read file tag yn
do
   if [ "${yn}" = 'yes' ]; then
      printf '/<head>/a\nabcd.....<%s> ...xyz\n.\nwq!\n' "${tag}"| ex - "${file}"
  fi
done < myFile

running 'tasha.sh', modifies 'source1' as:

Before Head
<head>
abcd.....<target1> ...xyz
## Text to be added
</head>

<BODY>
dskls
</BODY>