- Community Home
- >
- Servers and Operating Systems
- >
- Operating System - Linux
- >
- System Administration
- >
- Replace in a string
-
- Forums
-
- Advancing Life & Work
- Advantage EX
- Alliances
- Around the Storage Block
- HPE Ezmeral: Uncut
- OEM Solutions
- Servers & Systems: The Right Compute
- Tech Insights
- The Cloud Experience Everywhere
- HPE Blog, Austria, Germany & Switzerland
- Blog HPE, France
- HPE Blog, Italy
- HPE Blog, Japan
- HPE Blog, Middle East
- HPE Blog, Russia
- HPE Blog, Saudi Arabia
- HPE Blog, South Africa
- HPE Blog, UK & Ireland
-
Blogs
- Advancing Life & Work
- Advantage EX
- Alliances
- Around the Storage Block
- HPE Blog, Latin America
- HPE Blog, Middle East
- HPE Blog, Saudi Arabia
- HPE Blog, South Africa
- HPE Blog, UK & Ireland
- HPE Ezmeral: Uncut
- OEM Solutions
- Servers & Systems: The Right Compute
- Tech Insights
- The Cloud Experience Everywhere
-
Information
- Community
- Welcome
- Getting Started
- FAQ
- Ranking Overview
- Rules of Participation
- Tips and Tricks
- Resources
- Announcements
- Email us
- Feedback
- Information Libraries
- Integrated Systems
- Networking
- Servers
- Storage
- Other HPE Sites
- Support Center
- Aruba Airheads Community
- Enterprise.nxt
- HPE Dev Community
- Cloud28+ Community
- Marketplace
-
Forums
-
Blogs
-
Information
-
English
- 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
- Email to a Friend
- 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
- Email to a Friend
- 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
- Email to a Friend
- Report Inappropriate Content
06-02-2009 10:58 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- 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
- Email to a Friend
- 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
- Email to a Friend
- 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
- Email to a Friend
- 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
- Email to a Friend
- 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
- Email to a Friend
- Report Inappropriate Content
06-03-2009 07:46 AM
06-03-2009 07:46 AM
Re: Replace in a string
Bests Regards
Den
Hewlett Packard Enterprise International
- Communities
- HPE Blogs and Forum
© Copyright 2021 Hewlett Packard Enterprise Development LP