0

I want to replace a Marker (like ###marker###) inside a file with XML text (<networkConnector bla="blubb"/>...)

The text i want to insert is already generated in my script and is stored in a variable ($CONNECTIONS)

Is there a simple way to do that with Bash script?

sehe
  • 374,641
  • 47
  • 450
  • 633
Laures
  • 5,389
  • 11
  • 50
  • 76

2 Answers2

2
sed -i "s/###marker###/$CONNECTIONS/g" file.txt
sehe
  • 374,641
  • 47
  • 450
  • 633
  • i tried that long ago. sed: -e expression #1, char 58: unknown option to `s' – Laures May 31 '11 at 12:45
  • perhaps your $CONNECTIONS contains 'funny' characters. Try something like `sed -i "s~###marker###~$CONNECTIONS~g" file.txt` assuming `~` doesn't occur. (otherwise, post the value of $CONNECTIONS you are testing with) – sehe May 31 '11 at 12:50
  • just noticed that stackoverflow deleted my example. Connections contains xml so of cause there are some letters that sed doesn't like (for example spaces). I solved my problem using a perl script i found. http://hellem.org/blog/index.php/2010/04/16/bash-insert-content-of-one-file-into-another-file?blog=6 – Laures May 31 '11 at 13:14
0

I solved my problem using a perl script i found.

http://hellem.org/blog/index.php/2010/04/16/bash-insert-content-of-one-file-into-another-file?blog=6

Laures
  • 5,389
  • 11
  • 50
  • 76