1

Lets say I have a line #SYM

I need to replace it with all lines from file1.txt

Is it possible to do that with sed?

I have tried sed 's/#SYM/file1.txt/' updater

But that doesn't work, because I need to load file1.txt as string, and I do not know how to do that.

EDIT: I believe that there could be a way to do it in a shell script somehow.

EDIT2: I also just tried this:

#!/bin/bash value=$(<tools/symlink) sed -i 's/#SYM/$value/' META-INF/com/google/android/updater-script

John Bielowski
  • 169
  • 1
  • 8

1 Answers1

2

Use r command:

sed -e '/#SYM/ {r tools/symlink' -e 'd}' META-INF/com/google/android/updater-script
  • /#SYM/ {r tools/symlink if a line contains #SYM, append the contents of tools/symlink
  • d} then delete the matching line
  • the two commands are separated using -e option because everything after r is considered as part of filename

Add the -i option once you are satisifed that it is working

Sundeep
  • 19,273
  • 2
  • 19
  • 42
  • its working, but if i add -i, it says sed: -e expression #1, char 2: unexpected `}' – John Bielowski May 29 '20 at 07:30
  • are you using `GNU sed` or some other implementation? see https://stackoverflow.com/questions/5694228/sed-in-place-flag-that-works-both-on-mac-bsd-and-linux – Sundeep May 29 '20 at 07:31