I'm trying to take the contents of a file and insert it after a matching pattern in another file using sed. My question is very similar to this question, but I wish to insert the contents of a file inline rather than on a new line. How can I do this?
Using the example question I referenced, the first answer does exactly what I want; however, I want the insertion to happen inline:
sed '/First/r file1.txt' infile.txt
The actual data I want to insert is a JSON file:
[
{
"foo": "bar",
"baz": "biff",
"data": [
{
"a": 1945619,
"b": [
{
"c": 512665,
"d": "futz"
}
]
}
]
}
]
Best Answer
In your linked question there is already good
awk
answer, just modify it a little bit by usingprintf
instead ofprint
to insert the content without newline:Result:
You may want to add space or other delimeter after "First" with
printf $0 " "; ...
If inserted file has many lines then:
Result: