- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: search & replace in all files
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
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-21-2011 10:21 PM
07-21-2011 10:21 PM
Hi guys ,
i would like to search for a patern in all subdirectories and then replace the same with another name..
say grep "hello" in /home/test to be replaced with "world" in all the files under /home/test
Solved! Go to Solution.
- Tags:
- sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2011 12:59 AM
07-22-2011 12:59 AM
Re: search n r eplace in all files
find ./ -type f -exec sed -i ‘s/string1/string2/’ {} \;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2011 04:02 AM
07-22-2011 04:02 AM
Re: search & replace in all files
>find ./ -type f -exec sed -i ‘s/string1/string2/’ {} \;
HP-UX's sed doesn't have -i.
Also your sed replacement will do substrings.
And if the file doesn't have string1, do you really want to change the modification time?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2011 05:08 AM
07-22-2011 05:08 AM
Solution
@Dennis Handly wrote:>find ./ -type f -exec sed -i ‘s/string1/string2/’ {} \;
HP-UX's sed doesn't have -i.
Also your sed replacement will do substrings.
And if the file doesn't have string1, do you really want to change the modification time?
Hi:
As noted, HP-UX 'sed' lacks the GNU extension for in-place editing. Perl doesn't and it's available on virtually every HP-UX platform. Perl's regular expressions can easily address matching substrings or not, too. As for not updating files without matches, this one-liner would need to be enhanced slightly. All said:
# find . -type f -exec perl -pi.old -e ‘s/\bstring1\b/string2/’ {} +
This will process multiple files for every Perl process forked. Files will be updated in-place with a backup before modification as "*.old". The addition of the '\b' (boundry) surrounding the string to be matched tightens the criteria for replacement.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2011 05:27 AM
07-22-2011 05:27 AM
Re: search & replace in all files
hi Guys ,
I went ahead with the perl option given by James.
It worked like a charm....for me modification time was not imp..just the replacement was.
Thanks .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2011 05:28 AM
07-22-2011 05:28 AM
Re: search & replace in all files
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2011 05:37 AM
07-22-2011 05:37 AM
Re: search & replace in all files
>Thanks Dennis for the -i option info
Note: GNU sed has that -i.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2011 06:04 AM
07-22-2011 06:04 AM
Re: search & replace in all files
@Dennis Handly wrote:>Thanks Dennis for the -i option info
Note: GNU sed has that -i.
Dennis, that's what I noted in my original response :-) You usually read better ;-)
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2011 06:51 AM
07-22-2011 06:51 AM
Re: search & replace in all files
>that's what I noted in my original response
I guess I read that as Linux, rather than gnu that you could install on your HP-UX system.