Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unix join separator char

Tags:

join

unix

csv

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.

like image 250
Federico Giorgi Avatar asked Nov 12 '09 13:11

Federico Giorgi


People also ask

What is the JOIN command in Unix?

What is the join command in UNIX? The join command in UNIX is a command line utility for joining lines of two files on a common field. It can be used to join two files by selecting fields within the line and joining the files on them. The result is written to standard output.

How to specify a field separator for joining using the joincommand?

To specify a field separator for joining using the joincommand use the -toption. An example is a CSV file where the separator is ,. In the following example there are two files names.csvand deposits.csv.

How to join lines of two files in Unix?

The join command in UNIX is a command line utility for joining lines of two files on a common field. It can be used to join two files by selecting fields within the line and joining the files on them. The result is written to standard output. How to join two files

How to make a JOIN command only print pairable lines?

1. using -a FILENUM option : Now, sometimes it is possible that one of the files contain extra fields so what join command does in that case is that by default, it only prints pairable lines.


3 Answers

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

Try

join file1 file12 -t $'\t'
like image 93
Tonio Avatar answered Sep 30 '22 13:09

Tonio


You can enter tab by pressing CTRL+v Tab

join -t '<CTRL+v><Tab>' file1 file2
like image 27
citrin Avatar answered Sep 30 '22 11:09

citrin


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".

like image 3
tflutre Avatar answered Sep 30 '22 11:09

tflutre