Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Join several lines in a single one, inside a single file or from several files.

join is a utility in Unix systems that takes two files and a field number for each and outputs a file where the lines with an identical field in both are merged.

For example, given a file a:

a hey
b how are you ?
c ok

and a file b:

a hi
b fine, thank you
d er...

join -1 1 -2 1 a b outputs:

a hey hi                                           
b how are you ? fine, thank you

"Join" is also a common operation in text editors. Joining several lines means basically removing the end of lines between them (and optionally, replacing them with regular spaces), effectively making them a single line.

history | excerpt history