- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- 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
12-12-2007 10:51 AM
12-12-2007 10:51 AM
How to search and replace a particuler word in all the files starting from a particular directory /opt/usr ?
Thanks,
Shiv
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2007 11:02 AM
12-12-2007 11:02 AM
SolutionSimply:
# cd /path && find . -type f -exec perl -pi -e 's/\bworld\b/shiv/' \+
This would find only *files* in '/path' containing the string "world" and replace it with "shiv". Only strings bounded by non-word characters (e.g. whitespace) are matched and substituted. Hence, "hello world" becomes "hello shiv" but "hello worldly" remains unaltered.
If you want to preseve a copy of any files before modification, do:
# # cd /path && find . -type f -exec perl -pi.old -e 's/\bworld\b/shiv/' \+
...the backup copy of each file will be named with the suffix ".old".
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2007 11:28 AM
12-12-2007 11:28 AM
Re: Search and replace
create a script with instruction:
mv $1 `echo $1 | sed s/veinte/treinta/`
and Execute:
find /directory -name *expression* -exec script \{\} \;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2007 05:31 PM
12-12-2007 05:31 PM
Re: Search and replace
echo "line 1\nline 2" | chgafile -ws line Line
Line 1
Line 2
chgafile debug "--> DEBUG <--" myfile
(previews the changed lines, leaves myfile unchanged)
chgafile -w debug "--> DEBUG <--" myfile
Previews the changes and also writes the changes to myfile.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2007 01:12 AM
12-13-2007 01:12 AM
Re: Search and replace
I use this script (no perl used) to change files
HTH,
Art