World is Welcome To The World of Linux

Journey into the world of linux

Menu
  • About
  • Welcome
Menu

How To Join Two Files Vertically

Posted on April 12, 2009 by Ganesh Sharma

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

In Unix, sometimes we come across situations where we need to join two files’ output side by side vertically. This is also referred to as vertical joining of files. In such situations, paste command comes handy. With the help of this command you not only can vertically join the files, but insert some delimiter as well.

Here is the brief illustration of paste command. Let’s take an example. Let’s say we have three files: objects, connection, properties. Just names. Nothing specific to Operating System. The contents of files are listed below.

wiw Labs:$ cat objects
Sun
Tree
Sky
Water
Night
Day

wiw Labs:$ cat connection
is
is
is
is
is
is

wiw Labs:$ cat properties
Red
Green
Blue
Colorless
Dark
Bright

wiw Labs:$ cat atlast
O Really!!!
O Really!!!
O Really!!!
O Really!!!
O Really!!!
O Really!!!

Let’s see what happens when we use paste command. The general format of paste command is:
paste -d file1 file2 file3

wiw Labs:$ paste objects connection properties
Sun is Red
Tree is Green
Sky is Blue
Water is Colorless
Night is Dark
Day is Bright

By default, the paste command inserts a TAB in between corresponding rows from different files.

Now, let’s say we want to use the delimiter as a single space, then:

wiw Labs:$ paste -d ” ” objects connection properties
Sun is Red
Tree is Green
Sky is Blue
Water is Colorless
Night is Dark
Day is Bright

Now, this TAB becomes a single space. The delimiter can be only a single character.

Let’s see if we specify more than one delimiter in paste command:

wsd007:$ paste -d “;:>” objects connection properties atlast
Sun;is:Red>O Really!!!
Tree;is:Green>O Really!!!
Sky;is:Blue>O Really!!!
Water;is:Colorless>O Really!!!
Night;is:Dark>O Really!!!
Day;is:Bright>O Really!!!

Did you notice something strange? Yes. The first and second file will use first delimiter to join(semicolon in this case). The second and third file will take second delimiter to join(colon in this case). The third and fourth file will take the third delimiter to join(> in this case). And so on.

And last case, you can paste or join the outputs of other command also through pipe.

wiw Labs:$ cat objects|paste -d” ” – connection|paste -d ” ” – properties
Sun is Red
Tree is Green
Sky is Blue
Water is Colorless
Night is Dark
Day is Bright

If you notice, ‘-‘ is used as a place holder for the output of the command. For example, you see:
paste -d” ” – connection
so, “-” will be filled by the output of “cat objects”

Now see the opposite. The below output will clear your doubt:

wiw Labs:$ cat objects|paste -d” ” connection – |paste -d ” ” properties –
Red is Sun
Green is Tree
Blue is Sky
Colorless is Water
Dark is Night
Bright is Day

There are many more wonderful things which you can do with paste command. But, tips and tricks should not be lengthy article. I’ll be writing more in some other context. If you find any problems in your day to day activities, do write me and I’ll try to bring out the solution.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • Date Command Tutorial(Video)
  • grep Command Tutorial – 1(Video)
  • Introduction To ls Command(Video)
  • Chapter 3
  • Set Position Of Poll Module Into Joomla

Recent Comments

  • Kansas City Trailer Proz on Physical Volume In AIX – A Primer
  • Create volume group in AIX | myunixsheet on How To Create Volume Group
  • Restore of AIX backup on other Unix system - TecHub on What is mksysb And What Are Its Components
  • Firewall Unleashed - InfoSec Institute on Packet Filtering Firewall: An Introduction
  • Manwendra on Proxy Firewall and Gateway Firewall: Introduction

Archives

  • January 2019
  • June 2010
  • May 2010
  • February 2010
  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • December 2008
  • November 2008

Categories

  • 30 Days To Joomla WebSite Setup
  • A Journey To The World of Linux System Administration
  • Aix
  • Backups
  • Books
  • Firewalls
  • Introduction
  • Joomla
  • Joomla Backup
  • Joomla Web Technology
  • Linux
  • LPAR and Virtualization
  • LVM
  • Pluggable Authentication Modules
  • section navigator pro
  • Security
  • Security Knowledge Base
  • Tips and Tricks
  • Uncategorized
  • World is Welcome Products

Meta

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org
©2023 World is Welcome To The World of Linux | WordPress Theme by SuperbThemes