1

I want to concatenate in BSD Join.

Data

Model Decreasing Constant Increasing
2025 75.5 82.5 89.5
2035 65.5 82.5 102
2050 49.5 82.5 112

and error configuration in ybar

Model Decreasing Constant Increasing
2025 2.5 2.5 2.5
2035 2.5 2.5 5
2050 7.5 7.5 7.5

which should be

2025 75.5 82.5 89.5 2.5 2.5 2.5
...

Unix variant join A B does work according to my friend.

Outputs from Head

$ head model1_ave.dat
Year Decreasing Constant Increasing
2025 75.5 82.5 89.5
2035 65.5 82.5 102
2050 49.5 82.5 112
$ head model1_ave_err.dat 
Model Decreasing Constant Increasing
2025 2.5 2.5 2.5
2035 2.5 2.5 5
2050 7.5 7.5 7.5

How can you concatenate the two files in OSX Join i.e BSD?

  • Works for me with these files. Are you sure the line endings are unix-like and not DOS-style (DOS/Windows produce files with CR+LF at the end, unix tools prefer LF)? – nohillside Apr 19 '15 at 8:42
  • join -1 1 -2 1 <(grep -v Year model1_ave.dat) <(grep -v Model model1_ave_err.dat) works :-) – nohillside Apr 19 '15 at 9:42
1

join works for me here:

pse@Mithos:~/t$ join -1 1 -2 1 t1 t2
Model Decreasing Constant Increasing Decreasing Constant Increasing
2025 75.5 82.5 89.5 2.5 2.5 2.5
2035 65.5 82.5 102 2.5 2.5 5
2050 49.5 82.5 112 7.5 7.5 7.5

In case there are non-matching header lines in each file you need to get rid of them first, otherwise the joining will fail.

pse@Mithos:~/t$ join -1 1 -2 1 <(grep -v Year t1) <(grep -v Model t2)
2025 75.5 82.5 89.5 2.5 2.5 2.5
2035 65.5 82.5 102 2.5 2.5 5
2050 49.5 82.5 112 7.5 7.5 7.5
  • Thank you for your addition! So join considers the headers in doing the joining. – Léo Léopold Hertz 준영 Apr 19 '15 at 10:38
  • join doesn't know about headers in the first place, it just joins (or tries to) lines of text – nohillside Apr 19 '15 at 10:44
  • So the parameters -1 1 and -2 1 tells to join that use the first columns in the files as the pivot point if they are the same. When they were not the same, nothing come out. – Léo Léopold Hertz 준영 Apr 19 '15 at 10:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .