I need to append a file in a specific location of another file. I got the line number so, my file is:
file1.txt
:
I
am
Cookie
While the second one is
file2.txt
:
a
black
dog
named
So, after the solution, file1.txt
should be like
I
am
a
black
dog
named
Cookie
The solution should be compatible with the presence of characters like "
and /
in both files.
Any tool is ok as long as it's native (I mean, no new software installation).
Another option apart from what RavinderSingh13 suggested using sed
:
To add the text of file2.txt
into file1.txt
after a specific line:
sed -i '2 r file2.txt' file1.txt
Output:
I
am
a
black
dog
named
Cookie
Further to add the file after a matched pattern:
sed -i '/^YourPattern/ r file2.txt' file1.txt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With