Sonic84
Sonic84

Reputation: 991

Use SED to replace text in a XML with the contents of another file

I'm trying to search and replace " REPLACEME" with the contents of /tmp/dictionary.txt using SED.

I've tried a few other solutions mentioned on stack overflow, however they keep throwing errors: sed: 3: "# REPLACEME

Thank you!

script I'm using:

#!/bin/bash


sed '#          <string>REPLACEME</string># {
r /tmp/dictionary.txt
}' /tmp/plaintext.plist > palintext_ammended.plist

Upvotes: 1

Views: 179

Answers (2)

potong
potong

Reputation: 58473

This might work for you (GNU sed):

sed -e '/REPLACEME/{s//\n/;P;e cat dict.txt' -e 'D}' plain.txt

Upvotes: 1

anubhava
anubhava

Reputation: 785406

This should work:

sed -e '/<string>REPLACEME<\/string>/r /tmp/dictionary.txt' -e '//d' /tmp/plaintext.plist

sed only allows alternative delimiter for s (substitute) command. With # it will ignore rest of the command probably treating that as comment.

Upvotes: 2

Related Questions