I want to join 3 files on a column which has sorted unique numeric values (those files have only one column of values though) and starts with same prefix for an example "usi".

Now, while I am doing this

join -j 1 ../Test_Data/usi* > ../Test_Data/join_output.txt

I am finding following error:

join: extra operand `usi_rtree_lw_100000.txt'
Try `join --help' for more information.

Any ideas?


join accepts only 2 files to join. To operate on 3 file you have to use 2 join calls:

join -j 1 <(join -j 1 ../Test_Data/usi-1 ../Test_Data/usi-2) ../Test_Data/usi-3 > ../Test_Data/join_output.txt

The above command requires bash, as uses process substitution. If you use another shell, please specify which.

Update according to the comment.
If you know only a file name pattern instead of exact file names, let the shell expand the pattern, capture the expanded list in an array then use the array elements as parameters:

join -j 1 <(join -j 1 "${file[0]}" "${file[1]}") "${file[2]}"
| improve this answer | |
  • actually the problem is , I know only the prefixes of the files,I cant use the exact names of them. – Nawshad Farruque Oct 22 '12 at 7:54

POSIX shell variants of manatwork's answer:

  1. printf '"%s" ' ../Test_Data/usi* | { read a b c ; join $a $b | join - $c ; }

  2. set -- ../Test_Data/usi* ; join "$1" "$2" | join - "$3"

| improve this answer | |

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.