|
Automatically tell text file from binary file?
OK, this has eluded me for the longest time:
I need a way to distinguish a text file. This would be something that a Bash shell script could use. I write obsessively, and I'm stuck with out a dozen fantastically useful labor-saving shell scripts I could write because I don't have a way to test if a file is text or binary without having a C program open it, read a line of bytes from it, and close it!
Surely, there must be one of the little GNU/Unix programs that can be called with the right incantation from a batch script, probably with an obscure option set, which can return a boolean yes/no on whether the file contains ASCII text characters? I know the "less" program on some systems balks at binary files and asks if you'd like to see it anyway, but that's not good enough for automated script purposes.
This is such a basic function (represented on the character level frequently in languages like Python and C as the "isascii()" function or the "isprint()" function), that I'm positive there has to be one already in existence.
|