If I have 2 files where the first lines contain identical headings:

A.txt:

A
1
aa

B.txt

A
ee
7

I want to combine them like so:

C.txt

A
1
aa
ee
7

Is there a one liner to do this?

link|improve this question
Do you want this to happen only if the header is the same? – mattdm Dec 3 '10 at 13:05
Not necessary.. I'm thinking of a simple case when I know the headers are the same. Handling the case where the headers can be slightly different might be the subject of another question :-) – StamfordBingo Dec 3 '10 at 13:27
feedback

3 Answers

up vote 3 down vote accepted
tail -n +2 B.txt | cat A.txt - > C.txt
link|improve this answer
Thank you Ignacio; – StamfordBingo Dec 3 '10 at 13:29
feedback

If order is not a problem:

sort A.txt B.txt | uniq

link|improve this answer
1  
How will this result in the desired output? – Ignacio Vazquez-Abrams Dec 3 '10 at 13:06
feedback

Here's another way that's easily scalable to any number of input files (just add them as additional arguments:

awk 'FNR!=NR&&FNR==1{next}{print}' A.txt B.txt > C.txt
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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