suppose i have original file:
original.txt:
hello
how are you
you are wonderful
what time is it
I went to the store last night. and some apple juice
then i have another file:
anotherfile.txt:
with my friends mary, john and harry.
We had a great time.
We bought food
Suppose i want to add the content of anotherfile.txt right after the pattern "last night".
so the resulting output looks like this:
hello
how are you
you are wonderful
what time is it
I went to the store last night with my friends mary, john and harry.
We had a great time.
We bought food and some apple juice
I'd like to use awk for this. and the awk code i'm attempting to use is this:
awk '/last.*night/{printf $0; while(getline line<"anotherfile.txt"){print line};next}1' originalfile.txt > resultingfile.txt
for some reason, when i run the above command, it doesn't do anything. it just outputs the original file to resultingfile.txt