Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

This question already has an answer here:

Say I have multiple files x1, x2,x3,x4, all with common header date, time, year, age.

How can I merge them to one singe file X in shell scripting?

File x1:

date time year age
101014 1344 2012 52
111012 1200 2010 49

File x2:

date time year age
140112 1100 2011 54
230113 0500 2005 46

Similiary for other files x3 and x4.

The output should be:

date time year age
101014 1344 2012 52
111012 1200 2010 49
140112 1100 2011 54
230113 0500 2005 46

and the similar data from x3 and x4.

share|improve this question

marked as duplicate by cuonglm, terdon Sep 26 '14 at 14:29

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2 Answers 2

up vote 0 down vote accepted

An awk solution:

$ awk 'NR == 1 {print;next} FNR != 1' file1 file2
date time year age
101014 1344 2012 52
111012 1200 2010 49
140112 1100 2011 54
230113 0500 2005 46
share|improve this answer

Easy, you gonna use the join command. Don't remember by heart the argument. See the manual man join for more information.

share|improve this answer
    
If you don't remember the argument, please don't post an answer. Answers should actually answer the question. –  terdon Sep 26 '14 at 14:29

Not the answer you're looking for? Browse other questions tagged or ask your own question.