Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 03-14-2006, 10:32 AM   #1
LQ Newbie
Registered: Apr 2002
Location: Holland
Distribution: SuSe 8.0
Posts: 11

Rep: Reputation: 0
[bash / sed] remove all data between < >

Dear all,
question, I like to remove all data in a file which is between "<" and ">" and replace this with ||.

Example of original data:


this should become:

any good hint on how to do this?

Old 03-14-2006, 11:12 AM   #2
Andrew Benton
Senior Member
Registered: Aug 2003
Location: Birkenhead/Britain
Distribution: Linux From Scratch
Posts: 2,073

Rep: Reputation: 64
If you put the text in a file called test.txt
sed -i 's,<[a-z]*>,<||>,g' test.txt

Last edited by Andrew Benton; 03-14-2006 at 11:33 AM.
Old 03-14-2006, 09:49 PM   #3
Senior Member
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802

Rep: Reputation: 47
Old 03-15-2006, 04:21 AM   #4
LQ Newbie
Registered: Apr 2002
Location: Holland
Distribution: SuSe 8.0
Posts: 11

Original Poster
Rep: Reputation: 0
Originally Posted by Andrew Benton
If you put the text in a file called test.txt
sed -i 's,<[a-z]*>,<||>,g' test.txt
Thanks, seems to be working fine, however this is only working of I have data between < > which contains no special chars. If I have date end tags like </blabla> in the data it will mess up the entire data. I have tried some other options and tried to find a solution but the only thing I succeeded in was loosing a lot of sleep and I ended up with no solution.

Any good hints on how to handle this even in case in starts with </ or contains a "

Old 03-15-2006, 05:20 AM   #5
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.3, Oracle Linux, Mint
Posts: 9,703

Rep: Reputation: 412Reputation: 412Reputation: 412Reputation: 412Reputation: 412
sed 's/<[^>]*>/<||>/g' test.txt


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 - remove last four characters from string 3saul Linux - Software 9 12-14-2015 04:43 PM
using sed to remove word wrap Harpune Linux - Software 2 03-02-2009 06:53 PM
sed question: remove decoration from each line Hivemind Linux - Software 1 01-18-2006 07:13 AM
Using sed in bash to remove whitespace jimieee Programming 3 01-28-2004 10:33 AM
bash - sed/tr??? pk21 Programming 2 09-05-2003 07:56 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:56 PM.

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