LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how can i add 2 txt file into a different locations of another file? (https://www.linuxquestions.org/questions/linux-newbie-8/how-can-i-add-2-txt-file-into-a-different-locations-of-another-file-4175514948/)

pump1t 08-15-2014 07:22 AM

how can i add 2 txt file into a different locations of another file?
 
Hello guys,

I know sed can do this:
sed '40r textfile.txt' < aaa.conf > tempfile.txt

insert the contents of textfile.txt into line 40 of aaa.conf, but can i insert another text file into aaa.conf on line 100 in one command?

thanks very much!

thesnow 08-15-2014 08:41 AM

On my system that command just copies aaa.conf to tempfile.txt

Another option is to use head, cat, and tail

Code:

(head -40 aaa.conf && cat textfile.txt && tail -n +41 aaa.conf) > tempfile.txt
You can expand on that to insert again at line 100. It would be long and ugly, but if it absolutely has to fit on one line for some reason it can be done.


All times are GMT -5. The time now is 12:38 PM.