#!/usr/bin/env perl # # only - print all lines whose first field is in the given file # # see also: ./except # # $Id$ use strict; use warnings; use Getopt::Std; my %opt; getopts( 'hx', \%opt ); HELP_MESSAGE() if $opt{h}; sub HELP_MESSAGE { warn join( ' ', 'Error:', @_ ), "\n" if @_; print STDERR < 1 ) { my $f = shift(@ARGV); open( my $fh, as_input($f) ) or do { warn "cannot open $f, skipped\n"; next }; while (<$fh>) { ++$seen{$_} } close($fh); } { my $f = shift(@ARGV); open( my $fh, as_input($f) ) // die "cannot open $f, no output generated\n"; if ( $opt{x} ) { while (<$fh>) { print if !$seen{$_} } } else { while (<$fh>) { print if $seen{$_} } } close($fh) }