![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| dynamic editing using shell script | habzone2007 | Shell Programming and Scripting | 1 | 05-14-2008 11:55 PM |
| editing a file via a shell script ?? | jimmyc | Shell Programming and Scripting | 2 | 03-28-2008 12:21 PM |
| Editing file | rahul303 | Shell Programming and Scripting | 4 | 09-23-2007 11:49 PM |
| Editing the File using Awk | awk_beginner | Shell Programming and Scripting | 3 | 04-06-2007 11:43 AM |
| Editing a file in a shell script | jowpup | UNIX for Dummies Questions & Answers | 3 | 02-08-2005 04:45 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Editing a file using a script
Hi
I have about 10 config files belonging to software that runs on SCO UNIX. These files contain, amongst many other things, a path which points to the software locations. We normally have to change them manually every time the software is coppied to a new location and when you gotta do a few times a day, it becomes quite laboreous. I would like to know how to change all these paths using a single script. I'm hoping to have the user enter the 2 different paths once and let the script find the paths in these files (line numbers for the paths vary from file to file) and over write them with the new ones. It is worth noting that the only alterations that can be made to the config files are the path names. Anything else will cause the software that reads them, to disappear up its own backside. I hope I'm being clear and I look forward to some help ![]() |
|
||||
|
Thanks for your reply google.
Unfortunately I'm only a junior manager here and making changes to the software code itself isn't an option in my position unfortunately... the second way you propose is more up my street, but I'm not sure how to use the sed command. I've been working with UNIX for 2 days now ![]() I have written the script that coppies the software and the 10 files in queswtion, but it's a royal pain to edit these files every time. See my problem? |
|
||||
|
Use sed
As far as I understand sed can meet your requirements or you can even do a global replace in vi.
Open the file using vi ,type escape followed by : then type s/Oldpath/newpath/g .This should change the path through out the file.Also note that if your path contains "/" ,then you will have to escape it using a "\" For example: s/old_dir1\/old_dir2\/old_dir3/new_dir1\/new_dir2\/new_dir3/g alternately you can use sed sed 's/old_dir1\/old_dir2\/old_dir3/new_dir1\/new_dir2\/new_dir3/g' filename >new_filename Also if you want to pass the pathnames as argument then you can type a script containing sed which takes the path as arguments I haven't tried the last solution,but I don't see any major problem with it. Hope this helps Saurabh |
|
||||
|
Wouldn't you have to edit the script with the old and new directories every time? (which kinda defeats the purpose)
There are 152 variations (groups) of these 10 files knocking about in several servers and you choose at random a group of 10 to modify. None of the 152 variations are the same... Just to throw a spanner in the works and confuse everyone ![]() |
|
|||||
|
Here is the problem as I understand it.
1. You have a ton of scripts that have hard coded paths 2. Each time a new deployment occurs, you must edit the paths 3. Your sick of manually editing the paths! Proposal: -- Create a script that anyone can use that will do the following. 1. Copy the files in questions (deploy them were they need to be) 2. For each file and path that needs a change, Prompt the user with the existing directory paths. Ask user if this is correct (if so, exit) if not ask user to specify the path. 3. Validate the users input. 4. Backup the original config files that you are about to change. 5. Use sed to change the path by replacing the old path in the file with what the user just requested. 6. Work on a more robust deployment plan ![]() Here is a link to some sed info to get you started Last edited by google; 05-28-2003 at 12:20 PM.. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|