-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlgrep
More file actions
executable file
·59 lines (48 loc) · 1.21 KB
/
lgrep
File metadata and controls
executable file
·59 lines (48 loc) · 1.21 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/perl -w
use strict;
# lgrep: likeness-grep or l33t-grep
# Attempt to match things that may have been obfuscated by l33tspeak,
# possibly by marketers trying to avoid filters
# Note that this will tend to move towards letters, not away from it, so
# placing numbers or other nonnumerics in the search string is not
# recommended. It also lowercases everything for broader matching.
main(@ARGV);
############################
sub main
{
my @args = @_;
if(@args < 2)
{usage();}
my $pattern = lc shift @args;
foreach my $file (@args)
{
open(THISF, $file) || die "ERROR: Could not open [$file]:$!\n";
while(my $thisl = readline(THISF) )
{
my $match = 0;
$thisl =~ tr/\r\n\f//d;
my @parsings = interpret_line($thisl);
foreach my $parsing (@parsings)
{ # tempting to use grep(), but we want short-circuit
if($parsing =~ /$pattern/)
{$match++;last;}
}
if($match) {print "$file: $thisl\n"}
}
close(THISF);
}
}
sub interpret_line
{ # Interpret a line, return all plausible interpretations of it in a list
my ($inl) = @_;
$inl = lc($inl);
my @returner;
$inl =~ tr/150/iso/;
$inl =~ tr/3/e/;
push(@returner, $inl);
return @returner;
}
sub usage
{
die "Usage: lgrep PATTERN FILE [FILES..]\n";
}