Skip to content

Instantly share code, notes, and snippets.

@Integralist
Last active August 16, 2021 08:19
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Integralist/ff7065a6c74b7cf8bfd58fcd32dfd9f1 to your computer and use it in GitHub Desktop.
[Sed Replace Pattern with File Contents] #sed #bash #replace
cd -- "$(mktemp -d)"
printf '%s\n' 'nuts' 'bolts' > first_file.txt
printf '%s\n' 'foo' 'bar' 'baz' > second_file.txt
sed -e '/bar/r ./first_file.txt' second_file.txt
### output...
foo
bar
nuts
bolts
baz
### ...notice 'bar' in second_file.txt has the contents from first_file.txt appended after it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment