I have multiple script files that I have created, that allow me to simply replace a few tokens at the top of the file, and then not have to go through the actual script and change anything. I have about 10 of them, but I was hoping to find a way to write a small script that would allow me to input what value I want those tokens to hold, and then run that script, and it would go through all the scripts I have and replace the tokens with the values I input in to the first script.
Not sure if I explained it very well, but here's an example.
when I run replaceScript.sh, I'd like to be able to input, say, 5 variables(var1-var2-...var5), then the replaceScript.sh will go through and replace those same variables that have been set in serverScript1-3, with the values I input in to the replaceScript.sh
Yes, we can help you do that, but we need some examples
ie. input and expected output.
control file name control.ctl:
This will not always work, especially when you try to replace what are regex metacharacters.
Okay, I have about, 8 variables(now that I think about it, variable isn't the best name for them. More just tags that I have created in the following format to make it easy to replace them manually, which I am now trying to do with a script). All named in this format
@tag1@
@tag2@
@tag3@
etc
.
.
.
Now the text inside the @..@ tag doesn't follow the naming convention of tag1.2.3.4.... etc, but it was just easier to use that on here.
The file names that hold these tags are as follows:
startTestABC
stopTestABC
deleteABC
rotateABC
A little more information would be that those ABC scripts all set some variable equal to the tag, ie
TEST_NAME="@tag3@"
ANOT_VAR="@tag4@"
That way, when I run the script I can replace all the @...@ tags with what I need, and then the bottom of the script calls everything by the constant variable names.
I was thinking either the script has a header that I could vi it and change it b/c this script will be used over and over with different values for the tags each time. So, either a header section, or even an interactive script where it asks for the values, stores them, then uses those to run the replace command in each script.
Output is obviously the updated ABC script. It doesn't even need to create the new files, all it has to do is modify the existing script, b/c I have my directory which holds these scripts, and then when I use them I always have to move them somewhere else, and then run the replace script from the new directory.
I have multiple different scripts that use this same format and have the same variables and tags in each of them. Let's say I have hundreds of different things I need to run this script for. Right now it works fine, I just replace the @...@ tags manually each time I need a new set of scripts. That's the part I want to automate, I need a script where I can input the new tag values only once, and then that script will go through and replace the tags of my 10 scripts that use the same tags.
Looks like sed can do it, but I still haven't figured out the bst way to do it when I have 10 different strings I need to replace(that will be different everytime I run the replace.sh script) in 10 different files.
The replacement part itself ( replaceScript.sh script ) is not very hard. The point is that the *ABC scripts will be running multiple times, and after their first change through the replacement script, there won't be any more tags @..@ left in them ( or am I missing something here ? ), and you need to change those values back again in the future.
So how are you planning to rechange the new values ( other,1001,20,...) to the old tag values @..@, for the next run ?
Are the variable names VAR_MAN_NAME, VAR_PORT_NUM,..., the same in all *ABC scripts ? If so, you can replace their values based on their unique names in all the files.
Another way, you might use their same record number ( NR ) in all the files, if they are in the same position.
I think you need to provide more details about the unique properties of these variables.
The replacement part itself ( replaceScript.sh script ) is not very hard. The point is that the *ABC scripts will be running multiple times, and after their first change through the replacement script, there won't be any more tags @..@ left in them ( or am I missing something here ? ), and you need to change those values back again in the future.
So how are you planning to rechange the new values ( other,1001,20,...) to the old tag values @..@, for the next run ?
Are the variable names VAR_MAN_NAME, VAR_PORT_NUM,..., the same in all *ABC scripts ? If so, you can replace their values based on their unique names in all the files.
Another way, you might use their same record number ( NR ) in all the files, if they are in the same position.
I think you need to provide more details about the unique properties of these variables.
I didn't explain this part very well.
The ABC scripts I have in a separate directory. What I'm going to do is copy all those ABC scripts to a different directory along with the replace.sh script. Then I'll run the replace script. So I'll still have the originals untouched, and then the new ones are what I'll use for that. Then I can do the same thing with the original ABC scripts, whenever I need to replace the @...@ tokens with something else.
Edit:
to add to that, the name of the scripts are always going to be static, and won't change, that's why I just want to copy them to a temp directory, run the script, and then I can do what I need to with them. No need to rename the files or anything like that.
Good Evening Folks -
Happy Friday!
I have a need to replace a certain string in all .csv files from "0.00" to "#Missing" in my /app/hyp_app/files directory.
Does anyone have a script they use regularly that's rather quick in performance? My files are rather large so I'm looking for a... (5 Replies)
Hi
can someone help me to resolve the error
for this condition
if ] && ]; then
i am passing the values $k and $kkm
i am getting the error like "-: more tokens expected"
Thanks in Advance (5 Replies)
Hi all
This is my first post. Please bear with me with all my mistakes. I started learning shell since couple of days now and this might be quite basic for all, i want to search for files in a directory containing specific string and replace it with new string. The code i wrote is quite bulky... (2 Replies)
Hey guys. I know pratically 0 about Linux, so could anyone please give me instructions on how to accomplish this ?
The distro is RedHat 4.1.2 and i need to find and replace a multiple lines string in several php files across subdirectories.
So lets say im at root/dir1/dir2/ , when i execute... (12 Replies)
Hi All,
Im writing a shell script in which I want to get the folder names in one folder to be used in for loop.
I have used:
packsName=$(cd ~/packs/Acquisitions; ls -l| awk '{print $9}')
echo $packsName
o/p: opt temp user1 user2
ie. Im getting the output as a string.
But I want... (3 Replies)
I have app log files that need to be cleansed for readability, and my sed skills are not adequate.
Each line has a long multi-segment header, which I am trying to remove, example below:
: 2010.05.26 20:38:00.640--DatabaseSessionImpl(21447570)--Connection(26209441)--Thread(Thread)--SELECT... (4 Replies)
I have a rather complicated search and replace I need to do among several dozen files and over a hundred occurrences. My site is written in PHP and throughout the old code, you will find things like
die("Operation Aborted due to.....");
For my new design skins for the site, I need to get... (2 Replies)
I used the following script
cd pathname
for y in `ls *`;
do sed "s/ABCD/DCBA/g" $y > temp; mv temp $y;
done
and it worked fine for finding and replacing strings with names etc. in all files of the given path.
I'm trying to replace a string which consists of path (location of file)
... (11 Replies)
Hi,
How do I parse/split lines (strings) read from a file and display the individual tokens in a shell script? Given that the length of individual lines is not constant and number of tokens in each line is also not constant.
The input file could be as below:
... (3 Replies)
hi guys,
Suppose you have 100 files in a folder and you want to replace all occurances of a word say "ABCD" in those files with "DCBA", how would you do
it ???
jatin (13 Replies)