I'm trying to replace a line in a file and here is my current shell script:
sed -i "s%$line%$line_formatted%g" $file_source
Whenever I try to replace $line
with $line_formatted
I get this error:
sed: -e expression #1, char 81: unknown option to `s'
I was just wondering what the correct syntax would be?
Giving the below comment a try, it still doesn't replace the text. Here is the code I used:
echo "Here is line: "$line
echo "Here is line_formatted: "$line_formatted
# sed -i "s%$line%$line_formatted%g" $topicJRXML_file_source
awk -v old="$line" -v new="$line_formatted" '
s=index($0,old) { $0 = substr($0,1,s-1) new substr($0,s+length(old)) }
' $topicJRXML_file_source
cp "$topicJRXML_file_source" "$topicJRXML_file_destination"
echo "Here is line after awk: "$line
And this is my console output:
Here is line: <property name="adhoc.display" value="Awk Test"/>
Here is line_formatted: <property name="adhoc.display" value="$R{CUSTOM.Awk_Test.LABEL}"/>
Here is line after awk: <property name="adhoc.display" value="Awk Test"/>