I am trying to insert a /file/path as string at the beginning of the file and have sed returning the code 100, but it is replacing all my files contents:
printf "Message\nMessage\nMessage\n" > test.tex;
sed -i "\@^@{ 1s@^@% Message\n@; q100}" test.tex;
cat test.tex;
Outputs:
% Message
Message
If I try to put 1s
on the beginning:
sed -i "\1s@^@{ 1s@^@% Message\n@; q100}" test.tex
It throws the error:
sed: -e expression #1, char 32: unexpected `}'
References:
- Return code of sed for no match
- How can I pass correctly the parameter `q` with value 100 to my sed expression?
Update
I just noticed it does not make any sense having the return code as 100, so I can just do
sed '1s@^@% Message\n@'
But for curiosity, would this be possible?
Update 2
The correct output would be:
% Message
Message
Message
Message
That is, keep the initial 3 files Message
I added to the file.