Lab Assignment, Foundations of Computing

Revised March 10, use your browsers Reload or Refresh button to get the latest version.


Write an awk program to check file type.

Name the program afile. The program reads from standard input. The program writes one line containing one word to standard output, indicating the type of the input: HTML, Scheme, Numeric, Text, or Other.

This example shows one way to run the program on a file named foo.dat. Here afile detects that foo.dat contains numeric data:


    $ cat foo.dat | awk -f afile

    Numeric

The criteria used to identify each type of file are described in these pages, and summarized in line here:

To understand the definition of the text file type, it may be useful to refer to a table of ASCII codes. Here are some samples from the web:

The file types are not mutually exclusive -- the first three file types are also text files -- so your program must test for file type in this order: HTML, Scheme, Numeric, Text and Other. So Text really means the file is a text file which is not also an HTML file, Scheme file, or Numeric file. The Other category should include binary files including GIF's, JPEG's, executable code (as found in the files in the bin directories) etc.

The assignment is due in the lab on Thursday, March 15.