#!/usr/bin/perl # grepl: # This script reproduces the functionality of 'grep -l' # The first command-line argument should be the pattern (regex) to look for. # The remaining command-line arguments are the filenames to look in. # # This is useful since there are some patterns that are difficult with 'grep'. # E.g.: grepl '[\000-\010]|[\013-\037]|\177' file1 file2 file3 # to search for files with control characters # Cameron Hayne (macdev@hayne.net) December 2006 use warnings; use strict; die "Usage: grepl pattern file1 [file2 ...]\n" unless scalar(@ARGV) >= 2; my $pattern = shift @ARGV; while (<>) { if (/$pattern/o) { print "$ARGV\n"; # output name of current file seek(ARGV, 0, 2); # go on to next file } }