I currently have a sed command that matches a specific phrase in a file, and replaces all lines of that file with the full text of a different file. This works for the phrase "### REPLACE EVERYTHING AFTER THIS LINE ###"
sed -n -e '1,/^### REPLACE EVERYTHING AFTER THIS LINE ###$/{ p; d; }' \
-e 'r replacement_file.txt' \
-e 'q' original_file.txt > original_file.txt.new &&
mv original_file.txt.new original_file.txt
This command works for text files, but in needing to replace files with javascript style comments, I've hit a bit of a snag. The new line/phrase I'm trying to match is now the following (and note I want to match this specific comment, not all comments that start with the double forward slash):
//REPLACE AFTER THIS
I've hit a snag as I'm currently failing to escape the double forward slash. I've tried escaping the two characters with a backslash, but that did not work. My current (non-working) command is the following:
sed -n -e ‘1,/^\/\/REPLACE AFTER THIS$/{ p; d; }’\
-e 'r replacement_file.txt' \
-e 'q' original_file.txt > original_file.txt.new && mv original_file.txt.new original_file.txt
Thanks in advance.
sed -n '\|^//|p'
\/\/
should work - if it doesn't, try making the match less specific e.g. removing the$
anchor in case there is trailing whitespace