So I am looking to edit a number of bits of a file prior to using it as an input file for model simulations. At the moment I am passing it back and forth between a couple of temporary files (it was a bit buggy when I tried to write to the same temporary file) before finally making a file I can use to run the model. Is there a way to get all this alterations made simultaneously? I reckon doing it the way I am now is probably quite inefficient. Example of code below:
sed -e "s/9000000.0/${naerval}/" MC_NAMELIST_Pin14_Run3.IN > /tmp/temp1.in
#sed is away to change a string in a text file
sed -e "s/8000000.0/${sig_aer}/" /tmp/temp1.in > /tmp/temp2.in
sed -e "s/7000000.0/${d_aer}/" /tmp/temp2.in > /tmp/temp1.in
sed -e "s/6000000.0/${t_twall}/" /tmp/temp1.in > /tmp/temp2.in
sed -e "s/5000000.0/${RH}/" /tmp/temp2.in > /tmp/temp1.in
sed -e "s/4000000.0/${Therm_Coeff}/" /tmp/temp1.in > /tmp/temp2.in
sed -e "s/3000000.0/${press_decay}/" /tmp/temp2.in > /tmp/temp1.in
sed -e "s/2000000.0/${kappa}/" /tmp/temp1.in > /tmp/NAMELIST.IN
./main.exe /tmp/NAMELIST.IN
I have additionally attempted replacing this code with:
sed -i.bak s~9000000.0~${naerval}~;s~8000000.0~${sig_aer}~;s~7000000.0~${d_aer}~;s~6000000.0~${t_twall}~;s~5000000.0~${RH}~;s~4000000.0~${Therm_Coeff}~;s~3000000.0~${press_decay}~;s~2000000.0~${kappa}~;" MC_NAMELIST_Pin14_Run3.IN > /tmp/NAMELIST.IN
./main.exe /tmp/NAMELIST.IN
However, this causes an error in main.exe while the original code does not. I assume therefore that this code does not alter MC_NAMELIST_Pin14_Run3.IN in the expected way.