SPUG: Checking for ASCII files
Daniel Pommert
dpommert at bestnet.com
Tue May 15 14:22:30 CDT 2001
On Unix, the standard way is with the file command.
The file command looks through the file until it is able
to come to some decision about what the file type is. If
it is presented with a new file type (say, weird binary)
it will say it is a text file. However, it uses a file
called /etc/magic, which you can modify, to decide what
a file is.
So, if you have specific binary files and then everything
else being text, run all of the binary files through the
file command. If it correctly recognizes all of them,
well and good. If not, educate the file command by
modifying /etc/magic.
After you have the file command working correctly, you
can run it from Perl to ask whether the file is text or
(known) binary.
I expect that there are also Perl modules on CPAN that will
use /etc/magic to examine and classify a file. However, I
don't know the specifics.
I hope this helps!
-- Daniel Pommert
-----Original Message-----
From: Lorraine Johnson
To: 'spug-list at pm.org'
Sent: 5/15/2001 11:46 AM
Subject: SPUG: Checking for ASCII files
Hello,
I'm sure this is an old question, but I'm obviously looking in the wrong
place for the answer.... We develop under Windows then copy source to
an
HP-UX box to build. (Long story.) We're writing a Unix Perl script to
navigate the directories and convert the Windows newlines to Unix
newlines.
We know all the pieces but one: What is the best way to determine if a
file
is ASCII or non-ASCII?
Thanks!
Lorraine
Lorraine Johnson
Senior Software Engineer
Elektrobit Inc.
lorraine.johnson at elektrobit.com
www.elektrobit-usa.com
v: (425) 445-1898
f: (425) 376-0235
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
Replace ACTION by subscribe or unsubscribe, EMAIL by your
Email-address
For daily traffic, use spug-list for LIST ; for weekly,
spug-list-digest
Seattle Perl Users Group (SPUG) Home Page:
http://www.halcyon.com/spug/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
For daily traffic, use spug-list for LIST ; for weekly, spug-list-digest
Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
More information about the spug-list
mailing list