- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Replace in a string
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
06-02-2009 10:15 AM
06-02-2009 10:15 AM
I've this in input
/logs/test/1/xxxx
I'd like to replace
/logs/
by
/logs_backup/
The result must be /logs_backup/test/1/xxxx
How to do this small trick?
Regards
Den
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2009 10:52 AM
06-02-2009 10:52 AM
Re: Replace in a string
A=/logs/test/1/xxxx
A=Transformed_string($A)
Now A = /logs_backup/test/1/xxxx
mkdir -p $A
Something like that ....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2009 10:58 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2009 11:18 AM
06-02-2009 11:18 AM
Re: Replace in a string
Is this will replace only the first occurence ?
Bests regards Ivan
Den
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2009 11:39 AM
06-02-2009 11:39 AM
Re: Replace in a string
> Is this will replace only the first occurence ?
Well, yes on a line-by-line basis. That is every _line_ in your input file will have the substitution performed _once_.
If you add the 'g' flag to the substitution, then every occurance on every line will be replaced:
# sed 's/logs/logs_backup/g' file
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2009 04:55 AM
06-03-2009 04:55 AM
Re: Replace in a string
ok. But if the replace string is
/su01/bazar/
instead of /logs_backup/
/logs/test/1/xxxx
=> /su01/bazar/test/1/xxxx
Bests regards
Den
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2009 06:33 AM
06-03-2009 06:33 AM
Re: Replace in a string
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2009 06:35 AM
06-03-2009 06:35 AM
Re: Replace in a string
> ok. But if the replace string is
/su01/bazar/
instead of /logs_backup/
Escape the forward slashes like:
# X=/logs/test/1/xxxx
# echo ${X}|sed -e 's/\/logs/\/su01\/bazar/g'
/su01/bazar/test/1/xxxx
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2009 07:46 AM
06-03-2009 07:46 AM
Re: Replace in a string
Bests Regards
Den