1

I'm having issues merging two files using the join command: The first file is a csv file:

NAIN GENIEU 01/01/1900,A,B
NAIN GENIEUR 01/01/1917,C,D
NAINGENIEUR 21/01/1917,E,F

The second file contains only the interesting id:

NAIN GENIEUR 01/01/1917

I would like this as output:

NAIN GENIEUR 01/01/1917,C,D

Both files are sorted with bash sort command. When I use join without any argument it default to spaces so it joints by PSEUDO but doesn't account for BIRTHDAY or anything after a space in PSEUDO. When I use -t","argument, I have no output at all (even though there should be)

Any clue on how to solve this? BTW I use join v.8.4

EDIT I tried putting quotation marks around the first field (which may contain spaces) but it doesn't help.

  • 2
    Please show us a more complete example and the output you expect to see. What you describe should work, if it doesn't, there's something going on with your data. Please edit your question and add a minimal example of the two files that reproduces the problem. – terdon Jun 10 '15 at 10:33
  • I edited my question, hope it makes it clearer – naingenieu Jun 10 '15 at 10:40
  • Sorry I meant csv file I didn't know they were different types. – naingenieu Jun 10 '15 at 10:41
  • @naingenieu There are multiple types all called CSV, but if you take advantage of the full range of things allowed, you cannot use line oriented tools like sed and join to work with them. – Anthon Jun 10 '15 at 10:42
  • @Anthon, my bad, didn't know, I corrected my question :-) thanks for the input! – naingenieu Jun 10 '15 at 10:44
1

Your fields do not match (at least in the example) The File that you are calling "full csv" has the field "PSEUDO BITHDAY" whereas the the second file has the field "PSEUDO BIRTHDAY" There is an extra R in the second file.

The option -t works well in all releases of join.

EDIT : Your example works for me

    bash-4.1$ join -t, a b
    NAIN GENIEUR 01/01/1917,C,D
    bash-4.1$ join --version
    join (GNU coreutils) 8.4
    Copyright (C) 2010 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.

    Written by Mike Haertel.
    bash-4.1$
  • My bad it was just a typo, i've remplaced it with examples. – naingenieu Jun 10 '15 at 10:49
  • You now seem to have leading blank spaces in tha master file on line 2 & 3 .. is that a typo too ? – amisax Jun 10 '15 at 11:00
  • No that seems to be a formatting issue one the website. – naingenieu Jun 10 '15 at 11:02
  • @naingenieu please see here for help on formatting. Tiny differences are important, you need to make sure that what we see is exactly what you have in your files. – terdon Jun 10 '15 at 11:20
1

Your command should work. However, at least in the example you show, you have a space at the end of the line in file2. That is important, it is taken as part of the field. As you can see, removing it joins the files as expected:

$ join -t"," -j 1 file1 file2  ## no output
$ sed -i 's/ $//' file2        ## remove the trailing space
$ join -t"," -j 1 file1 file2  ## now it works
NAIN GENIEUR 01/01/1917,C,D

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.