Long string insertion with sed
Posted
by
Luis Varca
on Server Fault
See other posts from Server Fault
or by Luis Varca
Published on 2013-10-29T09:24:32Z
Indexed on
2013/10/29
9:56 UTC
Read the original article
Hit count: 276
I am trying to use this expression to insert the contents of one text file into another after a give string. This is a simple bash script:
TEXT=`cat file1.txt`
sed -i "/teststring/a \
$TEXT" file2.txt
This returns an error, "sed: -e expression #1, char 37: unknown command: `M'"
The issue is in the fact that the contents of file1.txt are actually a private certificate so it's a large amount of text and unusual characters which seems to be causing an issue. If I replace $TEXT with a simple ASCII value it works but when it reads the large content of file1.txt it fails with that error.
Is there some way to carry out this action? Is my syntax off with sed or my quote placement wrong?
© Server Fault or respective owner