#!/bin/bash

a1=
a2=
if [ "$1" = -a1 ]
then
	a1=-a1
	shift
fi
if [ "$1" = -a2 ]
then
	a2=-a2
	shift
fi

fields="$1"
shift

if [ $# = 0 ]
then
	cat
else
	file="$1"
	shift
	combine $fields |
	nosql sort 1 |
	nosql join $a1 $a2 - <(
		< "$file" combine $fields |
		nosql sort 1
	) |
	uncombine $fields |
	mjoin $a1 $a2 "$fields" "$@"
fi
