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);' "[EMAIL PROTECTED]"
  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)' "[EMAIL PROTECTED]"
  fi
}


binfind () {
  if [ $# -eq 0 ] ; then
    binfind .
  else
    perl -MFile::Find -e 'find(sub{print "$File::Find::name\n" if (-f && -B);}, 
@ARGV);' "[EMAIL PROTECTED]"
  fi
}



-- 
GnuPG ID: B280F24E              Never could stand that dog.
alumni.unh.edu!kdc                   -- Tom Waits
_______________________________________________
gnhlug-discuss mailing list
gnhlug-discuss@mail.gnhlug.org
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/

Reply via email to