1

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?

2
  • Do you want this to happen only if the header is the same? Commented Dec 3, 2010 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 :-) Commented Dec 3, 2010 at 13:27

3 Answers 3

3
tail -n +2 B.txt | cat A.txt - > C.txt 
0
0

If order is not a problem:

sort A.txt B.txt | uniq

2
  • 1
    How will this result in the desired output? Commented Dec 3, 2010 at 13:06
  • This also deletes duplicate lines. Commented Sep 20, 2014 at 3:27
0

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 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.