LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Linux Sed Command Help (https://www.linuxquestions.org/questions/programming-9/linux-sed-command-help-224408/)

anirudh 08-30-2004 02:15 PM

Linux Sed Command Help
 
i have to replace a very large xml string with another large xml string
i am using sed but it does not work can anybody help me fix my problem
i am using sed as sed -e '1,$s/string1/string2/g' file1>>file2

the string1=<defns:Party xmlns:defns="://url1" xmlns:soapenc="://url1" xmlns:xsd="url1" xmlns:wsdl="url1:///" xmlns:ns5="url1://" xmlns:ns4="http://url2" xmlns:ns3="://url4" xmlns:ns2="://url5" xmlns:ns1="://url5" xmlns:xsi="://url3">

string2(the string to replace string1)=
party xmlns:defns="://url1" xmlns:soapenc="://url2/" xmlns:xsd="://url3" xmlns:wsdl="://url3" xmlns:ns5="://url4" xmlns:ns4="://url5/" xmlns:ns3="://url6" xmlns:ns2="://url7" xmlns:ns1="://url8" xmlns:xsi="://url9" xsi:noNamespaceSchemaLocation="://url10">

plz help

bruce ford 08-30-2004 02:42 PM

Hi,

when you escape all the slashes (i.e. preceeding them with a backslash) in both of your strings it works fine.

so long...
bruce

jlliagre 08-30-2004 02:49 PM

Three comments:

you can remove the redundant "1,$" from the command, sed is already processing by default all the lines,

you can also remove the "-e" option, as you only give one command;

finally, both of your strings are containing the "/" characters, so you can't use it as a separator, try instead:
sed "s#string1#string2#g"

edited:
bruce was faster that I and his suggestion works too, replacing the delimitors is IMO easier that backslashing the slashes though.

anirudh 08-31-2004 03:39 AM

thanks guys
for ur help

bruce ford 08-31-2004 02:09 PM

thanks jlliagre,
I didn't know about the delimiter replacement thing by now - you never stop discovering new things...

bruce


All times are GMT -5. The time now is 10:43 AM.