I am doing a research project that requires shell scripting, which I have almost no experience in, although I do have some programming experience. Here is the file in question:
export OMP_NUM_THREADS=12
read controls
#inlist directory
export MESA_INLIST="/home/nick/mesa-r11701/star/test_suite/rsp_Cepheid_grid/inlist"
I am borrowing this file to change the input of this second file /home/nick/mesa-r11701/star/test_suite/rsp_Cepheid_grid/inlist
.
RSP_mass = 4.165d0
RSP_Teff = 6050
RSP_L = 1438.8d0
RSP_X = 0.73d0
RSP_Z = 0.007d0
log_directory='LOGS_1'
photo_directory='photos_1'
And I want to assign different floats (or integers to concatenate to the 'photos_
and 'LOGS_
strings to change those from LOGS_1
to LOGS_2
, for example) to these several variables. Would I write my sed commands like so? I am not asking if this the only way to achieve this, but if this is the one of the correct ways for doing this.
read mass
read Teff
read L
read X
read Z
read d_number
sed -i -e "s/.*\(RSP_mass\).*/\1 = '$mass'/i" "$MESA_INLIST"
sed -i -e "s/.*\(RSP_Teff\).*/\1 = '$Teff'/i" "$MESA_INLIST"
sed -i -e "s/.*\(RSP_L\).*/\1 = '$L'/i" "$MESA_INLIST"
sed -i -e "s/.*\(RSP_X\).*/\1 = '$X'/i" "$MESA_INLIST"
sed -i -e "s/.*\(RSP_Z\).*/\1 = '$Z'/i" "$MESA_INLIST"
sed -i -e "s/.*\(log_directory\).*/\1 = 'LOGS_$d_number'/i" "$MESA_INLIST"
sed -i -e "s/.*\(photo_directory\).*/\1 = 'photos_$d_number'/i" "$MESA_INLIST"
To get context as to why I wrote the sed commands in this particular manner, please refer to the answer of my previous question.
=
? – thecep1 May 18 '20 at 01:35\(
to the beginning of the match, i.e.-e "s/^\([[:blank:]]*RSP_mass\).*/\1 = '$mass'/i" \
. You're already adding a space character before and after=
in your replacement (more consistent than in the input file). – Freddy May 18 '20 at 01:46