I try to make this very simple bash program that must make the following operations:
modify a file java n times: every time I must change a single word in a single line of the file (the line is 11) I know there is the following command that replace a single word in a particular line of a program wih another one:
sed -i "11s/1/$n/" IC_masslessPlanetesimal.java
if I do the above command I can modify only one time the file.java because in the second iteration of the for cycle I have not the same word as in the first iteration: I start with 1 in line 11, than in the fist iteration I change with
$n(that is equal to 2), but now HOW I can modify the
sedcommand to change again the word (that is now equal to 2) to have, for example, 3 in the 11th line?
compile the file java: it's ok;
modify a file.txt: again the same problem as in 1) I want to change a word in a line iteratively with a for cycle or something like that;
pass it to an executable file: this is the second problem. I have modifIed the param.txt file and now I want to read it into an executable file called exec. If I do this from the terminal I must launch the exec. program with the command
./execand after that I must write from screen the file.txt name. Now is it possible to launch a program from bash and read with it the file.txt? I try with:
sed -i "13s/Zero/$n/" param.txt ./exec < param.txt
that script must change the line 13 from Zero to $n in param.txt how I can launch the exec program with the command
./exec with the specific param.txt file.
#!/bin/bash n=0 for n in "2" "3" do sed -i "11s/1/$n/" IC_masslessPlanetesimal.java javac IC_masslessPlanetesimal.java java IC_masslessPlanetesimal sed -i "13s/Zero/$n/" param.txt ./exec < param.txt done
thanks a lot !!!