From this I found the command and it works without any command substitution. But if I try to substitute a variable in the command, I get the following problems.
Note: I am using sed command(BSD OSX) / MacOS
To reproduce just create a file.txt with this:
SOME_TEXT
CHANGE_THIS
CHANGE_THIS
CHANGE_THIS
Add TMP variable in you terminal:
TMP=export PATH=/Users/Name/with pace/and_variables:$PATH
Now with this command:
sed -i '' "1h; 1 $ { x; s/CHANGE_THIS/$TMP/; p; }" file.txt
I get this error:
sed: 1: "1h; 1 $ { x; s/CHANGE_T ...": invalid command code $
In a privious answer I got this("," added to "1,$":
sed -i '' "1h; 1,$ { x; s/CHANGE_THIS/$TMP/; p; }" file.txt
expected output file.txt
SOME_TEXT
export PATH=/Users/Name/with pace/and_variables:$PATH
CHANGE_THIS
CHANGE_THIS
I get this:
SOME_TEXT
SOME_TEXT
SOME_TEXT
SOME_TEXT