Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 08-15-2014, 07:22 AM   #1
LQ Newbie
Registered: Aug 2014
Posts: 5

Rep: Reputation: Disabled
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!
Old 08-15-2014, 08:41 AM   #2
Registered: Nov 2010
Location: Minneapolis, MN
Distribution: Ubuntu, Red Hat, Mint
Posts: 170

Rep: Reputation: 56
On my system that command just copies aaa.conf to tempfile.txt

Another option is to use head, cat, and tail

(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.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy the contents of a txt file to other txt files (with similar names) by cp command TheIndependentAquarius Linux - Newbie 7 07-03-2010 12:54 AM
Using key to match against source.txt file to add xml tags to names in Perl ginny2010 Programming 3 06-22-2010 01:16 PM
How do you add a .txt file to a domains base directory Trebore General 2 10-14-2009 02:47 PM
How can read from file.txt C++ where can save this file(file.txt) to start reading sam_22 Programming 1 01-11-2007 05:11 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:40 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration