30

Sorry for the maybe trivial question.

I fought a bit with the unix join command, trying to get tabs instead of whitespaces as the default separators. -t is the argument, but these don't work (ubuntu 9.10 64 bit 2.6.31-14, GNU coreutils version 7.4)

join file1 file2 -t"\t"
join file1 file2 -t="\t"
join file1 file2 -t="\\t"
join file1 file2 -t $"\t"

Et cetera. Of course, I can always use some inelegant solution like

join file1 file2 > output
sed "s/ /\t/g" output

But I wanted to look smart :-) Moreover, if there's a -t argument, it must work.

Timur Shtatland
  • 12,024
  • 2
  • 30
  • 47
Federico Giorgi
  • 10,495
  • 9
  • 42
  • 56
  • when use -t, as stated in man page, it says "Use character CHAR as the input and output field separator." when both your files have same terminator, then it works. – ghostdog74 Nov 12 '09 at 14:13

6 Answers6

60

I think it takes a variable generated on-the-fly

Try

join file1 file12 -t $'\t'
Tonio
  • 1,666
  • 2
  • 14
  • 12
6

You can enter tab by pressing CTRL+v Tab

join -t '<CTRL+v><Tab>' file1 file2
citrin
  • 725
  • 6
  • 9
3
join -t "`echo '\t'`" file1 file2

ps: on my machine, Red Hat Enterprise Linux Server release 5.1 (Tikanga), the command join -t $'\t' file1 file2 returns "Illegal variable name".

tflutre
  • 3,354
  • 9
  • 39
  • 53
3

An alternate trick that seems to work is to enclose the -t option in quotes with the literal tab character. This looks like:

join '-t    ' ...

with a variable space between the t and the closing quote (since it's a tab).

Typed, it's:

join<Spc>'-t<Ctrl-v><Tab>' ...
Tommy McGuire
  • 1,223
  • 13
  • 16
2

man join says, that the options have to come in front of the filenames. Have you tried

join -t "\t" file1 file2

?

Edit: Reflecting Tonio's answer, the correct line would read

join -t $'\t' file1 file2
Boldewyn
  • 81,211
  • 44
  • 156
  • 212
1

Other way is:

join -t "`echo -e "\t"`" file1 file2`

or in a more bash-fashion:

join -t "$(echo -e "\t")" file1 file

sebelk
  • 565
  • 1
  • 6
  • 16