- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Search and Replace
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
04-30-2008 11:47 AM
04-30-2008 11:47 AM
I want to replace string1 by string2 in some text files.
Actually I'm using a script mixeed with Perl and it works very well. Is there another possibility but without perl ?
...
find *.txt -type f -exec perl -i -pe 's|\string1\E|string2|g' {} \;
...
any idea ?
Regards
Den
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2008 11:51 AM
04-30-2008 11:51 AM
Re: Search and Replace
Change something in file & have it right back to same filename .
sed "s/old.info/new.info/g" file | tee file
Rgrds,
Rita
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2008 11:58 AM
04-30-2008 11:58 AM
Re: Search and Replace
The advantage to Perl is that this snippet performs an "inplace" update of every file found by the 'find' commmand in a very straightforware way.
You could use 'sed' to perform the substitution, but then you would have to redirect the output to a file of a *different* name. Then you have to rename the new output file to be that of the old input file to replace it.
This means that you really need to have a small script like:
#!/usr/bin/sh
sed -e s'|string1|string2|g' ${1} > ${1}.new
mv ${1}.new ${1}
...and do:
# find *.txt -type f -exec /usr/local/bin/mything {} \;
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2008 12:07 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2008 01:03 PM
04-30-2008 01:03 PM