#!/usr/bin/perl $grep = $ENV{'GREP'} || 'grep'; # grepw - case-insensitive grep stdin for all/any of the arg words in a line # Steve Kinzler, kinzler@cs.indiana.edu, Nov 04/Nov 05 # http://www.cs.indiana.edu/~kinzler/home.html#unix while ($ARGV[0] =~ /^-/) { $h = shift, next if $ARGV[0] eq '-?'; $o = shift, next if $ARGV[0] eq '-or'; $v = shift, next if $ARGV[0] eq '-v'; $args .= ' ' . shift; } # WARNING: -or not supported with all grep(1)'s print("usage: $0 [ -or ] [ -v ] [ $grep flags ] word ... -or match lines containing any of the words (default all) -v print the assembled shell command being run to stderr Words are case insensitive sequences of [a-z0-9_].\n"), exit if $h; @words = grep(/./, split(/\W+/, join(' ', @ARGV))); $cmd = "$grep -i$args '" . join('\|', @words) . "'" if $o; $cmd = "$grep -i$args " . join(" | $grep -i$args ", @words) if ! $o; print STDERR "$cmd\n" if $v; exec system $cmd;