9

Now,I have two files:

aaaa.txt:

a=0;
b=1;
c=2;

bbbb.txt:

d=3
e=4
f=5

I want to merge aaaa.txt and bbbb.txt to cccc.txt.

cccc.txt as follow:

a=0;d=3
b=1;e=4
c=2;f=5

So, what can I do for this?

Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501
binghenzq
  • 581
  • 2
  • 7
  • 13

1 Answers1

13

You can use paste for this:

paste -d '\0' aaaa.txt bbbb.txt > cccc.txt

From your question, it appears that the first file contains ; at the end. If it didn't, you could use that as the delimiter by using -d ';' instead.

Note that contrary to what one may think, with -d '\0', it's not pasting with a NUL character as the delimiter, but with an empty delimiter. That is the standard way to specify an empty delimiter. Some paste implementations like GNU paste allow paste -d '' for that, but it's neither standard nor portable (many other implementations will report an error about the missing delimiter if you use paste -d '').

Chris Down
  • 122,090
  • 24
  • 265
  • 262
  • @ Chris Down - Thank you very much, it working.By the way, another question: awk '{ sed 's/.*,/999/g' }' cccc.txt why it return awk: { sed s/.*,/999/g } awk: ^ syntax error. What's wrong with it? – binghenzq Nov 06 '13 at 04:45
  • I'm not totally sure what you're trying to do, but you can't just pass sed to awk like that... – Chris Down Nov 06 '13 at 05:14
  • @ Chris Down - Thans,I get it. – binghenzq Nov 06 '13 at 05:29
  • Please ask separate questions as, well, separate questions. It makes them useful for later users (possible to find!). – vonbrand Feb 15 '16 at 14:39