Pattern matching and replace in shell script

Hi

I want to find a line in a file which contains a word and replace the patterns.

Sample file content temp.xml

<applications>
    <application>
        Name="FirstService"
        location="http://my.website.selected/myfirstService/V1.0/myfirst.war"
    </application>
    <application>
        Name="FirstService"
        location="http://my.website.selected/mysecondService/V1.0/mysecond.war"
    </application>
</applications>

Now, I want to search a work "myfirstService" in above file and replace the line with say location="/home/usr/st.war" .

Same way.. I want to search a word mysecondService and replace with say location="/home/usr/sn.war"

Thanks,
Sakthi

You could try something like:

sed '/myfirstService/s,=.*,="/home/usr/st.war",
/mysecondService/s,=.*,="/home/usr/sn.war",' temp.xml

which for you sample input produces:

<applications>
    <application>
        Name="FirstService"
        location="/home/usr/st.war"
    </application>
    <application>
        Name="FirstService"
        location="/home/usr/sn.war"
    </application>
</applications>