LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-30-2004, 02:15 PM   #1
anirudh
Member
 
Registered: Aug 2004
Location: bangalore india
Posts: 50

Rep: Reputation: 15
Exclamation 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
 
Old 08-30-2004, 02:42 PM   #2
bruce ford
Member
 
Registered: Jul 2004
Location: Munich, Germany
Distribution: Sun Solaris 8, SuSE 9.0
Posts: 43

Rep: Reputation: 15
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
 
Old 08-30-2004, 02:49 PM   #3
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Ubuntu/WSL
Posts: 9,777

Rep: Reputation: 470Reputation: 470Reputation: 470Reputation: 470Reputation: 470
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.

Last edited by jlliagre; 08-30-2004 at 02:53 PM.
 
Old 08-31-2004, 03:39 AM   #4
anirudh
Member
 
Registered: Aug 2004
Location: bangalore india
Posts: 50

Original Poster
Rep: Reputation: 15
thanks guys
for ur help
 
Old 08-31-2004, 02:09 PM   #5
bruce ford
Member
 
Registered: Jul 2004
Location: Munich, Germany
Distribution: Sun Solaris 8, SuSE 9.0
Posts: 43

Rep: Reputation: 15
Thumbs up

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

bruce
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sed command Kalyani1 Linux - Software 28 12-07-2005 11:48 AM
Linux sed command kml100 Linux - Newbie 4 05-28-2004 03:27 PM
sed command linuxdev Linux - Newbie 9 02-24-2004 04:50 PM
sed Command linuxdev Linux - Newbie 3 02-09-2004 11:27 AM
sed command kwigibo Linux - General 3 04-21-2002 04:11 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration