How to Copy and Paste A Text File into Another Text File via Terminal

Let us view two example of text files namelyh textfile1.txt and textfile2.txt

# cat textfile1.txt
RedHat
Fedora
CentOS

# cat textfile2.txt
Enterprise Version
Core Version 9
Linux Distro

Now, let us merge or combine two text files using the linux paste command

# paste textfile1.txt textfile2.txt
result:
RedHat Enterprise Version
Fedora Core Version 9
CentOS Linux Distro

Making it permanent as file would be as easy as

# paste textfile1.txt textfile2.txt > output.txt

Did you noticed that the contents of textfile2.txt was merged with the data contents of textfile1.txt? Noticed also the fixed columnar width making the 2nd column word vertically aligned.

Merging two text file using paste could be very useful on specific scenarios of merging related data contents.

Here’s another scenario.

# cat test1.txt
Citybank
Citybank
BPI Bank
Citybank

# cat test2.txt
New York, USA
San Francisco, USA
Manila, Philippines
London, UK

Again, using paste to merge contents of first file and second text file

# paste test1.txt test2.txt
result:
Citybank New York, USA
Citybank San Francisco, USA
BPI Bank Manila, Philippines
Citybank London, UK

If you want to insert a delimeter character between two columnar data or data field, that could be done using the same linux paste command like so

# paste -d”, ” test1.txt test2.txt
result:
Citybank,New York, USA
Citybank,San Francisco, USA
BPI Bank,Manila, Philippines
Citybank,London, UK

Neat and nice, isn’t it? Hope you enjoy it, and oh, it was an old idea reminded to me by pinoyskull.

Merging two text files with a common field or column marker would be my next post, so watch out for it. And sorry for late updates, been very busy these past few weeks.

Gishore James

Manager Technology at Quikr
I am a highly successful, competent team member with a background of extensive hands-on project implementation experience. My success has been both internal to the companies to which I’ve contributed and external to clients and customers.Having the knowledge of setting up efficient & cost effective technology solutions, internet innovations, large scale IT implementations, helps me to find out the unique one in the way of my career.



Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>