Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|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
add comment

3 Answers

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

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
share|improve this answer
add comment

If order is not a problem:

sort A.txt B.txt | uniq

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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