-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathfgrep.pl
More file actions
37 lines (33 loc) · 700 Bytes
/
fgrep.pl
File metadata and controls
37 lines (33 loc) · 700 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Long qw(:config pass_through no_ignore_case);
my ($file, $remove, $delim) = ("", 0, "\t");
GetOptions (
"file:s" => \$file,
"v|remove" => \$remove,
"delim:s" => \$delim,
);
die "Usage: fgrep.pl [-v] [-d <delimiter] -f <filewithpatterns> <file to be searched>\n" unless $file;
open FILE, "<$file" or die "Could not open file with patterns\n";
my %hash;
while (<FILE>)
{
chomp;
$hash{$_}++
}
while (my $line = <>)
{
chomp $line;
my $found = 0;
foreach (split(/$delim/,$line))
{
if (exists $hash{$_})
{
$found = 1;
last
}
}
print "$line\n" if $found and not $remove;
print "$line\n" if not $found and $remove;
}