0

I have two files each containing hexadecimal numbers one on each line. The two files have the same number of numbers (hence the same number of lines).

I'd like to combine the two files into one but have the numbers displayed side by side, in two columns. So

file A has:

a1
a2
a3

file B has:

b1
b2
b3

I'd like a file that looks like:

a1 b1
a2 b2
a3 b3

Is there a way do do this? join looks like a candidate, but I've been playing around with it, and I can't get it to work. (Join seems to work on the premise of keys and sorted values.)

rici
  • 234,347
  • 28
  • 237
  • 341
Bitdiot
  • 1,506
  • 2
  • 16
  • 30
  • why bash? I'm pretty sure it's not hard to do using `read`, but it's extremely easy e.g. in python. I always encourage people to use the right tools for the right job, and bash is not the tool of choice for string processing, imho. – Marcus Müller Jun 01 '15 at 15:53
  • Well, it started out as a bash script. I'd like the whole script to stay in one language than mixing it. It's just a helper script to help in testing and development. It's not gonna be used anywhere outside my personal bin. – Bitdiot Jun 01 '15 at 15:59

1 Answers1

8

Use paste:

paste A B

That will separate the lines from A and the lines from B with a tab character. If you want them separated with a space instead, use

paste -d' ' A B
rici
  • 234,347
  • 28
  • 237
  • 341
  • 2
    nice, I didn't know paste. – Marcus Müller Jun 01 '15 at 15:54
  • Cool thanks. But, I can't seem to use bash process substitution with this. Doesn't look like past <(shell command1) <(shell command2) works. I can make temporary files, but I was hoping to use this nifty bash4 feature. – Bitdiot Jun 01 '15 at 15:56
  • 1
    @Bitdiot: In what way do you find that that fails? It certainly works for me. – rici Jun 01 '15 at 16:02
  • Exactly. Something like `paste <(seq 10) <(seq 5)` works perfectly fine. – fedorqui Jun 01 '15 at 16:03
  • 1
    @Bitdiot: By the way, process substitution is not a bash 4 feature. It's been in bash for a long time. – rici Jun 01 '15 at 16:04
  • It does work for me. Sorry about that. I didn't know it was a feature prior to bash4. But, thanks for that too. Anyways, great answer. Makes my script look cleaner! – Bitdiot Jun 01 '15 at 16:05