R sfst 1000.0000
$ new time step for mass scaled calculation
R dt2ms -4.000E-7
$ friction value for blank
R mue 0.120000
$ blankholder force
R bhf 2.0000E+5
$ simulation time
R endtime 0.150000
i want to change the value on the line containing 'mue'
with following I can read it but cant change it.
awk ' /mue/ { print $3 } ' input.txt
The value is to be taken from another file fric.txt.
fric.txt contains only numbers, one on each line .
awk 'BEGIN{while(getline line <"fric.txt"){k++;val[k]=line;}}/mue/{i++;$3=val;print;}' file
Input:
file:
R sfst 1000.0000
$ new time step for mass scaled calculation
R dt2ms -4.000E-7
$ friction value for blank
R mue 0.120000
$ blankholder force
R mue 0.130000
R bhf 2.0000E+5
R mue 0.140000
$ simulation time
R endtime 0.150000
fric.txt
1.120000
2.130000
6.140000
Output
R sfst 1000.0000
$ new time step for mass scaled calculation
R dt2ms -4.000E-7
$ friction value for blank
R mue 1.120000
$ blankholder force
R mue 2.130000
R bhf 2.0000E+5
R mue 6.140000
$ simulation time
R endtime 0.150000
I put the number in front of mue from the fric.txt . Then I delete the top line so that he lower line bubbles up to the top ready to be taken in the next step and so on.
yes the fric.txt change each time. giving the number for input file.