- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: edit script
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
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-05-2006 05:46 PM
07-05-2006 05:46 PM
I need to change a heap of lines in a heap of scripts the changes are directory names.
eg /opt/CA/sche needs to change to /opt/CA/Umja/sche
I seeem to remember there is a way to make changes like this relatively quickly. Does anyone know of a way?
pleanty points around
thanks Maria
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2006 05:54 PM
07-05-2006 05:54 PM
Re: edit script
The tool of choice is sed.
Here is some sample code.
The essense the sed s/search/replacewith/g command.
So create a file list with fill path. Put it in a file called /tmp/filelist
while read -r $filename
do
sed s/juf.org/juf.net/g ${filename} > ${filename}.bck"
mv ${filename}.bck ${filename}
done < /tmp/filelist
Please test this out before using it in production. The slashes will require a slight upgrade of my basic code.
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-05-2006 05:56 PM
07-05-2006 05:56 PM
Re: edit script
sed 's/\opt\/CA\/sche/\/opt\/CA\/Umja\/sche/g' your_scripts
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2006 06:24 PM
07-05-2006 06:24 PM
Re: edit script
# perl -li -e's{/opt/CA/sche\b}{/opt/CA/Umja/sche}g' all the files you want changed
Or, if you want to change all *files* recursively from a folder/directory
# find dir -type f | xargs perl -li -e's{/opt/CA/sche\b}{/opt/CA/Umja/sche}g'
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2006 07:10 PM
07-05-2006 07:10 PM
Re: edit script
to /opt/CA/sche/UM inside all the files in the directory, including if the path name has further directories added on to it?
I am an absolute novice with perl and sed. (that's probably the most helpful piece of info I can give you!)
thanks
Maria.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2006 07:33 PM
07-05-2006 07:33 PM
Re: edit script
If you only need to change files in one single dir, and not in subdirs,
# cd that_dir
# perl -li -e's{/opt/CA/sche\b}{/opt/CA/Umja/sche}g' *
will change all files for you. All occurannces.
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2006 01:57 AM
07-06-2006 01:57 AM
Re: edit script
I have not been able to get result with the perl command..but with the sed command - I been testing on one file only - I issue the command and the actual script that I want the changes to take place in, scrolls past with the necesary test changes. But, then, I issue the more command to view slowly the entire contents of the file and there are NO changes !! What is happening? do you know?
thyanks
Maria
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2006 02:12 AM
07-06-2006 02:12 AM
Solutionsed command itself does not make the changes to the original file. When you run it, it gives you the changed output to the stdout which is your terminal.
assuming you are using RAC's one-liner sed command, you can do this:
cd /my/scripts/directory
for script in `ls`
do
cat ${script} | sed 's/\opt\/CA\/sche/\/opt\/CA\/Umja\/sche/g' > ${script}.new
done
this will generate a new file with .new appended to the original filename in the same directory, which will be the modified version.
Hope this helps
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2006 02:13 AM
07-06-2006 02:13 AM
Re: edit script
It sounds as though you're not redirecting the output from sed to a file, so it's being displayed on stdout. Make sure to use this syntax:
sed s/juf.org/juf.net/g file_in > file_out
Then 'more file_out'.
PCS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2006 02:33 AM
07-06-2006 02:33 AM
Re: edit script
perl -pi -e's|/opt/CA/sche\b|/opt/CA/Umja/sche|g' *
And if you wanted to save an old copy
perl -pi.old -e's|/opt/CA/sche\b|/opt/CA/Umja/sche|g' *
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2006 02:39 AM
07-06-2006 02:39 AM
Re: edit script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2006 02:49 AM
07-06-2006 02:49 AM
Re: edit script
perl -li -e
is wrong
perl -pi -e
is correct.
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2006 03:50 AM
07-06-2006 03:50 AM
Re: edit script
Mel, I used your method and it worked well for me. The only thing I altered was number of slashes in the command:
sed 's/\opt\/CA\/sche/\opt\/CA\/UnicenterUUJMA\/sche/g' maria
I have learnt plenty tonight, thankyou.
Maria