I fought with it for so long but I am now completely out of ideas. Maybe someone here will be able to help me. Here is what I want to achieve:
file_1.txt:
# Some comment
some_variable="test"
some other things
# Marker
More things!@#$%^
file_2.txt:
# Marker
# Some other comment
other_variable_1="test"
# Some totally other comment
other_variable_2="test"
I want to insert file_2.txt into file_1.txt in place of # Marker and later I want to reverse this process.
Final file file_1.txt:
# Some comment
some_variable="test"
some other things
# Marker
# Some other comment
other_variable_1="test"
# Some totally other comment
other_variable_2="test"
More things!@#$%^
Problem is, both files are multiline and contains various special characters. I would also like to have both of those files in variables.
I tried various things, sed, perl and awk. Nothing worked for me. This is my closest attempt I think:
perl -pi -e 'chomp if eof' file_2.txt
marker_var="# Marker"
file_2_var=$(tr '\n' '\f' <file_2.txt)
sed -e "s|$marker_var|$file_2_var| tr '\f' '\n'" file_1.txt
I say closest because it it still not working. I tried to combine various answers from stackexchange but It throws error about not properly ended s. I suspected that it is because of final \n new line in file so I tried to delete it with perl command but it didn't work.
Can someone please help me?