home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / unix / question / 14976 < prev    next >
Encoding:
Text File  |  1992-12-26  |  1.1 KB  |  35 lines

  1. Newsgroups: comp.unix.questions
  2. Path: sparky!uunet!nwnexus!Celestial.COM!bill
  3. From: bill@Celestial.COM (Bill Campbell)
  4. Subject: Re: How to tell if you have an ASCII file
  5. Organization: Celestial Software, Mercer Island, WA
  6. Distribution: usa
  7. Date: Sat, 26 Dec 1992 17:02:53 GMT
  8. Message-ID: <1992Dec26.170253.10375@Celestial.COM>
  9. References: <1992Dec22.152123.5852@Cadence.COM>
  10. Keywords: ASCII
  11. Lines: 22
  12.  
  13. In <1992Dec22.152123.5852@Cadence.COM> dew@rocky.cadence.com (Dave Wilson) writes:
  14.  
  15. :I would like to be able to quickly tell if the file I am opening is ASCII text
  16. :or some binary executable or data file.  Is there any way of foolproof way of doing this?
  17.  
  18. In perl you can use the -T test:
  19.     if (-T 'filename') {
  20.         print "is text";
  21.     }
  22.     else {
  23.         print "not text";
  24.     }
  25.  
  26. This works well, but might be fooled by a text file that had
  27. non-ascii data (control codes imbedded in strings).
  28.  
  29. Bill
  30. -- 
  31. INTERNET:  bill@Celestial.COM   Bill Campbell; Celestial Software
  32. UUCP:   ...!thebes!camco!bill   6641 East Mercer Way
  33.              uunet!camco!bill   Mercer Island, WA 98040; (206) 947-5591
  34. SPEED COSTS MONEY -- HOW FAST DO YOU WANT TO GO?
  35.