开发者

unix join separator char

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开发者_StackOverflow中文版 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.


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

Try

join file1 file12 -t $'\t'


You can enter tab by pressing CTRL+v Tab

join -t '<CTRL+v><Tab>' file1 file2


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


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


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


Other way is:

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

or in a more bash-fashion:

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜