Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: is text file?



I use this in ~/zsh-fns/only-text-files:

# Filter out non-text-files from the argument list
# Usage: grep -c foo `only-text-files *`
file -f =(for i in "$@"; do print $i; done) |\
   awk -F: '{name = $1; $1 = ""; if ($0 ~ / text( |$)/) { print name }}'

I think it's important to use "file", as that is the system-supported way
of testing whether a file contains text.  The file man page also
strongly encourages the use of the string "text" in files which are
text, so it's pretty reliable to use the regexp (one possible exception
is postscript files).

Greg J. Badros
gjb@xxxxxxxxxxxxxxxxx
Seattle, WA  USA
http://www.cs.washington.edu/homes/gjb



Messages sorted by: Reverse Date, Date, Thread, Author