Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Jan 202010

Join lines on a common field


Suppose you have two files


john b
mark c
peter a


john 2
mark 3
peter 1

You can to join two files by the first column, to become

john b 2
mark c 3
peter a 1

It is easy with the join command

# join file1.txt file2.txt

Remark: You would need to sort the file and make each column an unique line first.

 Leave a Reply



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>