LinuxQuestions.org
Visit Jeremy's Blog.
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 10-29-2014, 01:02 AM   #1
Almaz
Member
 
Registered: Jul 2013
Posts: 35

Rep: Reputation: Disabled
append file to 2nd line file2


I'm trying to get sed working but I can't get it to work
1st_file
1
5


2nd_file
2
3
4

output
1
2
3
4
5

NOTE: text can be anything, numbers are just for example

sed -i "2i $2nd_file" $1st_file

What's the proper way to do it?

Last edited by Almaz; 10-29-2014 at 04:39 AM.
 
Old 10-29-2014, 03:34 AM   #2
kaz2100
Senior Member
 
Registered: Apr 2005
Location: Penguin land, with apple, no gates
Distribution: Debian testing woody(32) sarge etch lenny squeeze(+64) wheezy jessie stretch
Posts: 1,599

Rep: Reputation: 97
Hya

Is "join" what you are looking for?

You need to some additional tweak, tho.

cheers
 
Old 10-29-2014, 05:47 AM   #3
eklavya
Member
 
Registered: Mar 2013
Posts: 619

Rep: Reputation: 136Reputation: 136
If you want to insert all contents of 2nd_file into 1st_file at line no. 2, Run
Code:
sed -e "1r /path/of/2nd_file" /path/of/1st_file
It will insert all content of 2nd_file into 1st_file at line no. 2.
1r means "after line no. 1". It means "on line no. 2".

If you want to save this into third file
Code:
sed -e "1r /path/of/2nd_file" /path/of/1st_file > 3rd_file

Last edited by eklavya; 10-29-2014 at 06:05 AM.
 
2 members found this post helpful.
Old 10-29-2014, 02:31 PM   #4
Almaz
Member
 
Registered: Jul 2013
Posts: 35

Original Poster
Rep: Reputation: Disabled
Thanks Eklavya. That's exactly what I needed it
Code:
sed -i "1r /path/of/2nd_file" /path/of/1st_file

Last edited by Almaz; 10-29-2014 at 02:43 PM.
 
  


Reply


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
how to append text at the end of a line in a file mia_tech Linux - General 7 02-09-2014 11:56 PM
[SOLVED] Copy and replacing specific line from file1 to file2 line by line vjramana Programming 10 03-28-2011 08:49 AM
How to append text to the second line of a file SentralOrigin Programming 23 11-06-2010 08:19 PM
[Java] How to append something to each line in a text file ? Kunsheng Programming 3 04-15-2009 10:08 PM
append a line to text file in script roadrash Linux - Newbie 4 10-01-2008 10:03 AM


All times are GMT -5. The time now is 01:54 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration