- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- help with sed
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
Forums
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
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
02-27-2007 04:19 PM
02-27-2007 04:19 PM
help with sed
I am trying to read a line and replace 2nd occourring string using sed, but I am not able to do it. Can u pls help me with this. Or is there any other way I can do it.
here is the senario.
echo 00015-90002ALL|N|CE|ALL|IN|19981001|120540| ...now I want to replace this |ALL| with some other string.
The end result should be something like this.
00015-90002ALL|N|CE|AB|IN|19981001|120540|
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2007 04:51 PM
02-27-2007 04:51 PM
Re: help with sed
00015-90002ALL|N|CE|ab|IN|19981001|120540|
As you've show it, only the second "ALL" is
bounded by "|" on both sides, so replace that
whole thing ("|ALL|").
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2007 05:10 PM
02-27-2007 05:10 PM
Re: help with sed
This is the command I used
echo $staging_product_load | sed -e 's/'"|ALL|"'/'"$cntry"'' >> file.txt
I am using it inside a shell script, and its a C shell
but its giving me error
sed: Function s/|ALL|/BP cannot be parsed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2007 05:21 PM
02-27-2007 05:21 PM
Re: help with sed
Missing the final "/". Also, you seem to
have gone a little nuts with the quotation.
How about this (assuming that "$cntry"
doesn't have the vertical bars already)?:
echo "$staging_product_load" | sed -e "s/|ALL|/|$cntry|/"
Of course, if you expect a lot of exotic
characters in the strings, more complicated
quotation could be needed.
td176> cntry=ab
td176> echo "00015-90002ALL|N|CE|ALL|IN|19981001|120540|" | sed -e "s/|ALL|/|$cntry|/"
00015-90002ALL|N|CE|ab|IN|19981001|120540|
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2007 05:26 PM
02-27-2007 05:26 PM
Re: help with sed
I solved the problem ...now its working. I made minor modification from u'r previous reply. Its working fine.
Thanks a lot.