I am writing a script to replace three lines for input in a C++ code.This is the snippet of the C++ code whose inputs I want to change:
char outputFileName_ForBlueEdge[50] = "BlueEdge_SetA_PeriodRange1.dat"; //File with model parameters on the blue edge
char outputFileName_ForPositiveGrowthModels[50] = "PostiveGrowth_SetA_PeriodRange1.dat"; //File with model parameters that have positve growth rates
char log_directory_prefix[30] = "LOGS_A/LOGS_A"; //Prefix to log_directory, suffix is model number. This is where LINA file should be
And here is a minimal reproducible version of the bash script:
dir=$PWD
cplusplus_plotter="$dir"/BlueEdge_Plotter_V7.cpp
#Set B
sed -i
-e "s/^([[:blank:]]char outputFileName_ForBlueEdge[50])./\1 = "BlueEdge_SetB_PeriodRange1.dat"/i"
-e "s/^([[:blank:]]char outputFileName_ForPositiveGrowthModels[50])./\1 = "PostiveGrowth_SetB_PeriodRange1.dat"/i"
-e "s/^([[:blank:]]log_directory_prefix[30])./\1 = "LOGS_B/LOGS_B"/i"
"$cplusplus_plotter"
However, the C++ file never changes and I keep getting the error:
sed: -e expression #3, char 59: unknown option to `s'
/
as the sed pattern/replacement separator, but also have a/
in the replacement textLOGS_B/LOGS_B
. See for example How to replace a string with a string containing slash with sed? (this is likely why it is complaining about expression #3 specifically) – steeldriver Jun 26 '20 at 22:51