- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Replace the word in directories and sub-directorie...
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
07-24-2007 11:48 PM
07-24-2007 11:48 PM
Replace the word in directories and sub-directories
Please advise.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2007 11:52 PM
07-24-2007 11:52 PM
Re: Replace the word in directories and sub-directories
You can use sed command for this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2007 11:55 PM
07-24-2007 11:55 PM
Re: Replace the word in directories and sub-directories
The tool for this is sed
"sed s/indexnfweekly.html/index2.html/g ${filetoback} > $filetoback.bck"
What that little command does is change where it says indexnfweekly.html to a index2.html
find /directory -exec grep -l "yourtext" {} ;\ >list
while read -r oldfile
do
sed $oldfile > $oldfile.new > newfilename
mv $oldfile $newfile
done < list
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2007 12:05 AM
07-25-2007 12:05 AM
Re: Replace the word in directories and sub-directories
it is not clear if this renaming should apply to filenames or the contents of each file - please clarify.
- running such a command - whether file- or stringrenaming is performed will be desastrous in system directories
- what about binary files?
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2007 12:19 AM
07-25-2007 12:19 AM
Re: Replace the word in directories and sub-directories
Renaming should occur with the word test with \\Test within the files in a directory and subdirectories.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2007 12:34 AM
07-25-2007 12:34 AM
Re: Replace the word in directories and sub-directories
Thanks for the reply. Can I use the script as follows:
#!/bin/ksh
find /webdata/dev/ir/classes -exec grep -l "System" {} ;\ >list
oldfile=System
newfile=\\System
while read -r oldfile
do
sed $oldfile > $oldfile.new > newfilename
mv $oldfile $newfile
done < list
--------------------------
I want to replace System with \\System under /webdata/dev/ir/classes, where it has six directories in which the files which I want to change.
I really appreciate if you can help me out.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2007 12:45 AM
07-25-2007 12:45 AM
Re: Replace the word in directories and sub-directories
Erroring out at the following command:
find /webdata/dev/ir/classes -exec grep -| "System" {} ;\ >list
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2007 12:55 AM
07-25-2007 12:55 AM
Re: Replace the word in directories and sub-directories
You have *tranposed" the "\" and the ";". The syntax is:
# find /webdata/dev/ir/classes -exec grep -l "System" {} \; >list
Now, haveing said that, you *need* to limit your selection to only files!
# find /webdata/dev/ir/classes -type f -exec grep -l "System" {} \;\ >list
*AND* you can improve the performance by using a "+" in lieu of a ";"
# find /webdata/dev/ir/classes -type f -exec grep -l "System" {} \+ >list
Of course, non of the above address the presence of any binary files if they are potentially present.
Lastly, be advised that *every* file in your directory will be updated whether or not a substitution was actually needed.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2007 02:29 AM
07-25-2007 02:29 AM
Re: Replace the word in directories and sub-directories
#!/bin/ksh
#find /webdata/dev/ir/classes -exec grep -l "System" {} ;\ >list
find /webdata/dev/ir/classes -type f -exec grep -l "System" {} \;\ >list
oldfile=System
newfile=\\System
while read -r oldfile
do
sed $oldfile > $oldfile.new > newfilename
mv $oldfile $newfile
done < list
-------------------
# ./replace-word.ksh
find: 0652-018 An expression term lacks a required parameter.
./replace-word.ksh[4]: system: not found.
#ls /webdata/dev/ir/classes
bean
db
exception
load
report
tag
util
All the above subdirectories in /webdata/dev/ir/classes have files which should be replaced from System to \\System.
Please help me out!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2007 02:57 AM
07-25-2007 02:57 AM
Re: Replace the word in directories and sub-directories
You wrote "\;\" instead of "\;", For efficiency, I also suggested you use "\+".
There's more wrong with your entire syntax anyway. I think this is what you want:
cat ./filter
#!/ust/bin/sh
find webdata/dev/ir/classes -type f -exec grep -l "System" {} \; > list
while read -r oldfile
do
sed -e 's/System/\\\\System/g' ${oldfile} > ${oldfile}.new
mv ${oldfile}.new ${oldfile}
done < list
...NOTE that your post suggested that you want a double backslash. Hence, the syntax I used will give you that.
Regards!
...JRF...