- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- sed negative lookahead
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2012 01:39 PM
07-24-2012 01:39 PM
sed negative lookahead
Hello all,
I have a text file with data similar to the following:
<test>testdata-A&B-testdata</test>
<test>testdata-C&D-testdata</test>
<test>testdata-E&F-testdata</test>
<test>testdata-G&H-testdata</test>
<test>testdata-I&J-testdata</test>
I need to replace all instances of "&" with "&". The tricky part is that I need to replace all "&" only when NOT followed by amp;. Basically, I need every instance of & to read & in this file when I am done with it.
I have been trying to find a solution with sed to do this and stumbled on Negative Lookahead, which sounds promising. I am not even sure if this is the correct path to take and I am having a hard time with the syntax.
Does anyone have some advice or has encountered a similiar issue? Any help with this issue is greatly appreciated.
Thank you
--John
- Tags:
- sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2012 02:42 PM
07-24-2012 02:42 PM
Re: sed negative lookahead
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2012 05:46 PM
07-24-2012 05:46 PM
Re: sed negative lookahead
Perhaps the simplest way is to replace all "&" by "&" and then replace all "&amp;" by "&":
sed -e 's/&/\&/g' -e 's/&amp;/\&/g'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2012 01:29 PM
07-25-2012 01:29 PM
Re: sed negative lookahead
Thank you both for your solutions. I tested each and they both work perfectly.
Steven -- In my case, there should always be at least four characters after any & because of the closing tag for that line. So I wouldnt have to worry about a situation where the & doesn't have four characters after it.
Dennis -- Your solution seems so obvious, now that you brought it up.
Thanks again both of you.
--John