I created two files:
echo -e "1\n2\n3\n4\n5" > 123.txt
echo -e "a\nb\nc\nd\ne" > abc.txt
I want to get the file 123.txt
with the following contents:
1
2
3
b
c
d
4
5
So in other words insert the rows with numbers from 2 to 4 of the file abc.txt
into the file 123.txt
after the third line.
I have reviewed the many similar questions here, but did not find a suitable answer. Nevertheless I got the lines:
sed -n '2,4p' abc.txt
and put some text into the file after the third line:
sed -i '3a\mytext' 123.txt
How to do this using the previous command stdout or/and a sed
/awk
single command?
head -n +3 123.txt > tmp && cat abc.txt >> tmp && tail -n +2 123.txt >> tmp && mv tmp 123.txt
head -3 123.txt > tmp && tail -4 abc.txt | head -3 >> tmp && tail -2 123.txt >> tmp && mv tmp 123.txt