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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
03-14-2006, 10:32 AM
|
#1
|
|
LQ Newbie
Registered: Apr 2002
Location: Holland
Distribution: SuSe 8.0
Posts: 11
Rep:
|
[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.
|
|
|
|
03-14-2006, 11:12 AM
|
#2
|
|
Senior Member
Registered: Aug 2003
Location: Birkenhead/Britain
Distribution: Linux From Scratch
Posts: 2,073
Rep:
|
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.
|
|
|
|
03-14-2006, 09:49 PM
|
#3
|
|
Senior Member
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802
Rep:
|
|
|
|
|
03-15-2006, 04:21 AM
|
#4
|
|
LQ Newbie
Registered: Apr 2002
Location: Holland
Distribution: SuSe 8.0
Posts: 11
Original Poster
Rep:
|
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.
|
|
|
|
03-15-2006, 05:20 AM
|
#5
|
|
Moderator
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,326
|
Code:
sed 's/<[^>]*>/<||>/g' test.txt
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 02:10 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|