a question about GREP
Kevin D. Clark
kevin_d_clark at comcast.net
Fri Mar 23 22:39:11 EDT 2007
Here is another copy of my favorite shell functions, since I kindof
sent out garbled versions the first time.
I hope others find these to be useful.
--kevin
# txtfind, dostxtfind, and binfind all use Perl's -B and -T file
# test operations.
#
# Here are some relevant sections from the perlfunc documentation:
#
# The "-T" and "-B" switches work as follows. The first block or
# so of the file is examined for odd characters such as strange
# control codes or characters with the high bit set. If too many
# strange characters (>30%) are found, it is "-B" file, other-
# wise it is a "-T" file. Also, any file containing null in the
# first block is considered a binary file
# ...
# Both "-T" and "-B" return true on a null file.
#
# Caveat programmer.
txtfind () {
if [ $# -eq 0 ] ; then
txtfind .
else
perl -MFile::Find -e 'find(sub{print "$File::Find::name\n" if (-f && -T);}, @ARGV);' "${@}"
fi
}
dostxtfind () {
if [ $# -eq 0 ] ; then
dostxtfind .
else
perl -MFile::Find -e 'find(sub{
$crlf = 0;
$f = -f;
$T = -T;
@ARGV=($_);
binmode(ARGV);
((/\r\n/) && $crlf++) while(<>);
print "$File::Find::name $crnl\n"
if ($f && $T && $crlf);
}, @ARGV)' "${@}"
fi
}
binfind () {
if [ $# -eq 0 ] ; then
binfind .
else
perl -MFile::Find -e 'find(sub{print "$File::Find::name\n" if (-f && -B);}, @ARGV);' "${@}"
fi
}
--
GnuPG ID: B280F24E Never could stand that dog.
alumni.unh.edu!kdc -- Tom Waits
More information about the gnhlug-discuss
mailing list