#!/usr/bin/awk -f BEGIN { FS = "\t"; OFS = FS } 1 == NR { attributes = $0 tupleSize = NF FIRSTFILE = FILENAME next } 1 == FNR { if ( $0 != attributes ) { printf( "ERROR: %s is not union compatible with previous input.\n", FILENAME ) >>"/dev/stderr" printf( " Expecting \"%s\".\n", attributes ) >>"/dev/stderr" printf( " Got \"%s\".\n", $0 ) >>"/dev/stderr" aborting = 1 exit 1 } next } NF != tupleSize { print "ERROR: Wrong tuple size." >>"/dev/stderr" aborting = 1 exit 1 } { #print FIRSTFILE, FILENAME if ( FILENAME == FIRSTFILE ) { tuples[$0] = 1 } else { delete tuples[$0] } } END { if ( aborting ) exit 1 } END { print attributes for ( r in tuples ) { print r } }