LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 11-11-2005, 10:17 AM   #1
ckoniecny
Member
 
Registered: Oct 2005
Posts: 162

Rep: Reputation: 30
sed question


I'm trying to substitue HTML tags for XML tags.

For example:

Code:
sed 's/<HTML>/<article>/g' index.htm > tmp.xml
That works, but when I try to substitute the closing tag </HTML>, it errors out.

Code:
sed 's/</HTML>/</article>/g' index.htm > tmp.xml
Any ideas?
 
Old 11-11-2005, 10:24 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Hi,

The slash in /html and /article need to be escaped, or you need to use another seperator in sed.

sed 's/<\/HTML>/<\/article>/g' index.htm > tmp.xml
or
sed 's%</HTML>%</article>%g' index.htm > tmp.xml

Take the one you like best.

Hope this helps.
 
Old 11-11-2005, 10:25 AM   #3
oneandoneis2
Senior Member
 
Registered: Nov 2003
Location: London, England
Distribution: Ubuntu
Posts: 1,460

Rep: Reputation: 46
You need to add a / to tell sed to treat the HTML code as a literal /

It looks like you're saying replace "<" with HTML>

Either use s/<//HTML>/<//article>/g or s@</HTML>@</article>@g - the first tells it to treat the / as a / and not a divider, the second uses a different divider, which should also work.

**edit: Too slow!
 
Old 11-11-2005, 10:31 AM   #4
ckoniecny
Member
 
Registered: Oct 2005
Posts: 162

Original Poster
Rep: Reputation: 30
Awesome, both ways helped me for the both of you. Thanks!
 
  


Reply

Tags
sed


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sed question virendratp Programming 3 09-10-2004 04:21 AM
sed question sphynx Programming 6 04-28-2004 07:25 PM
little sed question freelinuxcpp Linux - Software 3 01-20-2004 08:36 AM
sed question zoomzoom Linux - Software 2 10-20-2003 05:04 PM
A question on 'sed' Barbarian Programming 4 04-11-2002 11:19 PM


All times are GMT -5. The time now is 02:23 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration