Issue
I need to replace a single value dt=DELTAT in a python file with 3 different numbers. For each number I want to create a new file lets call them file1.py,file2.py and file3.py here is my attempt. the variable dt only appears once in the python file so this should be easy but I can't quite seem to get it. the original file is lorenz_x.py
for k in {1..3};do
for i in 0.0001 0.0005 0.001;
do
sed -i -e "s/DELTAT/i/g" "$lorenz_x.py" > lorenzk_x.py/?k[]=i
done
done
Thanks for the help!
I was expecting to have 3 new files like I names above but instead I got lorenz.txt: line 4: lorenzk_x.py/?k[]=i: No such file or directory.
I used vi lorenz.txt to create the file and bash lorenz.txt to run it. note the .txt is irrelevant here in linux and my new file names will have extension .py
Solution
Would you please try the following:
#!/bin/bash
for i in 0.0001 0.0005 0.001; do
((k++))
sed -e "s/DELTAT/$i/g" lorenz_x.py > "lorenz${k}_x.py"
done
Save the code avobe as lorenz.sh
(or whatever name), and run with bash lorenz.sh
. Then three files lorenz1_x.py, lorenz2_x.py and lorenz3_x.py will be generated with corresponding number substitutions.
Answered By - tshiono Answer Checked By - Robin (WPSolving Admin)