Skip to main content

Combining and Splitting Data

CommandDescription
join file1 file2Combine lines with a common field
paste file1 file2Merge files side by side
split -l 1000 fileSplit file into parts of 1000 lines each
tee fileDisplay output and write it to a file simultaneously

Example:

cat data.txt | tee output.txt

Displays content on screen and saves it in output.txt.

Data1

cat data1.txt          

Output:

1 John
2 Yan
3 Ben

Data2

cat data2.txt 

Output:

1 IT
2 Owner
3 Finance

Join

Command:

join data1.txt data2.txt 

Output:

1 John IT
2 Yan Owner
3 Ben Finance

Paste

Command:

paste data1.txt data2.txt 

Output:

1 John	1 IT
2 Yan 2 Owner
3 Ben 3 Finance