This should be easy: I want to run sed against a literal string, not an input file. If you wonder why, it is to, for example edit values stored in variables, not necessarily text data.
When I do:
cat getGCC_MSISDN.tsk | sed -i 's/TEMP_MSISDN/'$1'/g' | java_gcc_soap_any.ksh
What should be the correct command? I want it to take my MSIDN from the file.
CodePudding user response:
Use printf
to print the literal string.
printf '%s\n' 'some_literal_string' | sed -i 's/TEMP_MSISDN/'$1'/g' | java_gcc_soap_any.ksh
CodePudding user response:
You can try things like:
printf '%s' "$s" | sed "s/TEMP_MSISDN/$1/g" | java_gcc_soap_any.ksh
but that is very fragile. If $1
contains /
, for instance, this will fail. You can try to fix that with things like:
printf '%s' "$s" | sed "s@TEMP_MSISDN@$1@g" | java_gcc_soap_any.ksh
but you're just trading one bad symbol for another and not really making the solution robust. If you are using bash
, you can also try things like:
printf '%s' "${s/TEMP_MSISDN/$1}" | java_gcc_soap_any.ksh