LinuxQuestions.org
Visit Jeremy's Blog.
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 03-14-2006, 10:32 AM   #1
Ljohan
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:

fghgdhdfs<dhsj>hjsdhajk<dshj>dhsjk
sdsd<hh>dhsjyuiw<hjsd>hdjkshjkasjdks<dhsj>

this should become:
fghgdhdfs<||>hjsdhajk<||>dhsjk
sdsd<||>dhsjyuiw<||>hdjkshjkasjdks<||>


any good hint on how to do this?

Regards,
Johan.
 
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
Code:
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
/bin/bash
Senior Member
 
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802

Rep: Reputation: 46
http://sed.sourceforge.net/grabbag/tutorials/
 
Old 03-15-2006, 04:21 AM   #4
Ljohan
LQ Newbie
 
Registered: Apr 2002
Location: Holland
Distribution: SuSe 8.0
Posts: 11

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Andrew Benton
If you put the text in a file called test.txt
Code:
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 "

Regards,
Johan.
 
Old 03-15-2006, 05:20 AM   #5
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,506

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


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 - remove last four characters from string 3saul Linux - Software 5 07-28-2014 06:25 AM
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


All times are GMT -5. The time now is 06:17 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