I trying to solve following problem. With great helps of others here, I can write and understand simple do loop in bash scripting.
Now I try to do this:
In "mein_directory" directory I need following first to
create let say 10 subdirectories, with name subdirectories1.... subdirectories10
then I need to copy file to each subdirectories,
and then I need to enter in to each subdirectories and change specific word in file that has been copy from main directory.
And this is my main problem at the moment, because I need to change a the specific word is actually a number and I need to change this number of an increment multibly by number of subdirectory
so my code looks like this:
#!/bin/bash
increment=10
for i in {1..10}; do
mkdir subdirectory_$i;
done
for d in */; do
cp FILE "$d";
done
for j in {1..10}; do
cd subdirectory_$j/
increment=increment*$j
sed -i 's/old_word old_digit/old_word old_digits+increment/g' CONTROL
cd ../;
done
So let say the in file "FILE" in subdirectory_1
I need to change following
from
Paul 10
to Paul 20
And in subdirectory_2
from
Paul 10
to Paul 30
Please does anybody know how to around this?
Thanks a lot
as the file you are copying seems to be a template - couldn't you just replace your 'Paul 10' with sth more special, so you simply can replace that always same thing?
in sed you then also can use your e.g. $increment
– rkn Jan 10 '15 at 01:23