I am using the standard join command to join two sorted files based on column1. The command is simple join file1 file2 > output_file.
But how do I join 3 or more fil
One can join multiple files (N>=2) by constructing a pipeline of joins recursively:
#!/bin/sh
# multijoin - join multiple files
join_rec() {
if [ $# -eq 1 ]; then
join - "$1"
else
f=$1; shift
join - "$f" | join_rec "$@"
fi
}
if [ $# -le 2 ]; then
join "$@"
else
f1=$1; f2=$2; shift 2
join "$f1" "$f2" | join_rec "$@"
fi