For some reason my output of join is strange and scrambled; here is the command I use:

join -t, -j 1 -o1.1,2.2,1.2  f1 f2

Where f1:


and f2:


The output is:


and I am at loss as to why the output of join is not as expected. I have checked my locale already, with no luck.

Any ideas?

  • 2
    Does the file have DOS line endings (CR LF)? Add the output of join -t, -j 1 -o1.1,2.2,1.2 f1 f2 | od -c please. – muru Jul 5 '18 at 6:15
  • Thanks, I did not know the od command ! Your intuition was right, it is DOS endings – Tiphaine Jul 5 '18 at 6:24

Your data file are DOS text files. Each line has a trailing carriage return character.

The output that you expect is


but since there is a carriage return after the 7 in 337 (from the DOS line-ending in the second file), the cursor moves back to the start of the line before printing ,87, overwriting 1,33 there.

Run dos2unix on the data files to convert them to Unix text files, or instruct whatever program that creates them to create Unix text files.

  • Thanks, indeed this is it. I suspected it at first but threw that idea of since the files were made by a colleague on MacOS, it it seems the python csv module output DOS files by default – Tiphaine Jul 5 '18 at 6:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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