Here I am printing the contents of the file which are not matching. I want to do a vice versa, i.e. print the lines of file1 (those which are matching in file2)
#!/usr/bin/perl
# create names lookup table from first file
my %names;
while (<>) {
(my $col1)= split / /, $_;
$names{$col1} = 1;
last if eof;
}
# scan second file
while (<>) {
print if /^(\S+).*/ && not $names{$1};
}
you can refer this Question Compare two files with first column and remove duplicate row from 2nd file in shell script. I don't want to remove duplicates, I only want to print those which match with the contents of column and leave others.
not
.