- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Change all the occurences of a text in multipl...
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
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
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
тАО10-24-2006 07:06 AM
тАО10-24-2006 07:06 AM
e.g I want to change the following in all the files.
A=X.Y.Z.com to
A=A.B.C.com
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-24-2006 07:12 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-24-2006 07:18 AM
тАО10-24-2006 07:18 AM
Re: Change all the occurences of a text in multiple files
for i in test test1 test2
do
mv ${i} ${i}.orig
sed s/A\=X.Y.Z.com/A=A.B.C.com/g ${i}.orig > ${i}
rm -f ${i}.orig
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-24-2006 07:31 AM
тАО10-24-2006 07:31 AM
Re: Change all the occurences of a text in multiple files
find . -type f -exec perl -pi'.bak' -e 's/A=X.Y.Z.com/A=A.B.C.com/g' {} \;
Yang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-24-2006 07:44 AM
тАО10-24-2006 07:44 AM
Re: Change all the occurences of a text in multiple files
A bit faster way avoids the '-exec' for every file found and thus eliminates spawning a separate process (Perl) for each file found:
# FILES=`find /path -xdev -type f`; perl -pi.old -e 's/A=X\.Y\.Z\.com/A=A.B.C.com/g' ${FILES}
...This example finds a *files* in '/path' and performs your replacement therein, in-place. A backup copy of each file is retained with the ".old" extension. Note that a "." is a metacharacter so it is escaped to match only "." character.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-24-2006 07:45 AM
тАО10-24-2006 07:45 AM
Re: Change all the occurences of a text in multiple files
Welcome to the forums !!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-24-2006 09:38 PM
тАО10-24-2006 09:38 PM
Re: Change all the occurences of a text in multiple files
as you see from the previous answers, there is more than one way to to it. In Patrick's solution I would introduce a small additional check, if the write operation really succeded:
for i in test test1 test2
do
mv ${i} ${i}.orig
if sed s/A\=X.Y.Z.com/A=A.B.C.com/g ${i}.orig > ${i}
then rm -f ${i}.orig
fi
done
Another possibility without (visible) temporary files is to generate an ed/ex program:
find . -type f | xargs fgrep -l A=X.Y.Z.com |
while read fnam
do
print e $fnam
print "g/A=X\.Y\.Z\.com/s//A=A.B.C.com/g"
print w
done | ex -
mfG Peter