-1

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'
thecep1
  • 31
  • 6

1 Answers1

1

Like this:

  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"

You can choose the delimiter you want (in ascii table).

I choose ! in last sed command, because you had 4 /.