LinuxQuestions.org
Review your favorite Linux distribution.
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
 
LinkBack Search this Thread
Old 11-11-2005, 09: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, 09:24 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
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, 09:25 AM   #3
oneandoneis2
Senior Member
 
Registered: Nov 2003
Location: West Sussex, England
Distribution: Gentoo
Posts: 1,457

Rep: Reputation: 45
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, 09: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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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


All times are GMT -5. The time now is 02:29 PM.

Main Menu
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