LinuxQuestions.org
Register a domain and help support LQ
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-06-2013, 11:46 AM   #1
vj776
LQ Newbie
 
Registered: Oct 2013
Posts: 1

Rep: Reputation: Disabled
How to concatanate two files


Hi i have just started learning Linux.
Please help me by answering below question

file1

ABCDEF
GHIJKLM
NOPQRST
UVWXYZ

file2
12345
6789

i want to have file3 as

ABCDEF
GHIJKLM
12345
6789
NOPQRST
UVWXYZ
Regards
Vijay
 
Old 10-06-2013, 12:03 PM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Do you want to insert the content of file 2 after the second line of file 1? Here are three solutions using sed, awk and pure bash respectively:
Code:
sed '2rfile2' file1
Code:
awk '!(NR % 3){while ( getline line < "file2" ) print line}1' file1
Code:
while read line
do
  echo "$line"
  if [[ $((++c)) -eq 2 ]]
  then
    cat file2
  fi
done < file1
Hope this helps.
 
1 members found this post helpful.
  


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
[SOLVED] Bash script to read through text files and find largest number in files pomico Programming 15 09-13-2012 02:07 PM
need to rsync only selected files (--files-from) also need to delete files on dest. ? BrianK Linux - General 5 10-22-2009 10:52 PM
ntfs hard drive mounted. but doesnt show all files , tar files ataomega Linux - Software 1 08-28-2009 01:47 PM
in copy files or ls files the command want to invert select some files how to?? hocheetiong Linux - Newbie 3 06-27-2008 07:32 AM
How to filter files in files and files which are in a sub-directory with "grep"? Piero Linux - Newbie 9 08-29-2003 03:38 AM


All times are GMT -5. The time now is 12:51 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration