#!/usr/bin/awk -f BEGIN { FS = "\t"; OFS = FS } 1 == NR { attributes = $0 tupleSize = NF 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 } { tuples[$0] = 1 } END { if ( aborting ) exit 1 } END { print attributes for ( r in tuples ) { print r } }