LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 08-15-2014, 07:22 AM   #1
pump1t
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
thesnow
Member
 
Registered: Nov 2010
Location: Minneapolis, MN
Distribution: Ubuntu, Red Hat, Mint
Posts: 172

Rep: Reputation: 56
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.
 
  


Reply



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 Aquarius_Girl 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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

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