3

I am joining two very simple sorted files but for some strange reason it is not working. f1.txt:

f1 abc
f2 mno
f3 pqr

f2.txt:

abc a1
mno a2
pqr a3

Command:

join -t '\t' f1.txt f2.txt -1 2 -2 1 > f3.txt

FYI in the f1,f2 files the space is a tab. But this is producing a blank f3.txt. Why is this happening? This is such a simple example of joining right?

1 Answer 1

2

Your \t isn't being interpreted as a tab character. To do that you could/should use an ANSI string so your command would become

join -t $'\t' f1.txt f2.txt -1 2 -2 1 > f3.txt

with the $ before the '\t' so it will be interpreted as a tab like you want.

A handy resource for quoting things with bash at least is available here

2
  • Hi thanks. it worked. I have just one more question if you know. whats the difference between sort -k2 and sort -k2,2 . I saw some examples but didnt understand quite well. Commented Sep 15, 2016 at 16:51
  • @ShabhriNaresh in general new questions should be asked as a new question, but for now if you do -k2 it will do sorting from field 2 until the end of the line as part of the sort, -k2,2 will do the sort based only on field 2, and not consider any other fields. -k2,3 would use just the second and third fields etc. The first number is the first field to consider, the second is the last Commented Sep 15, 2016 at 17:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .