Assignment Day | Friday, September 12, 2014 |
Due Date | Monday, September 22, 2014 |
- Learn File I/O
- Create Files
- Modify Permissions
(will provide a program that reads command line arguments using getopt().). coming soon!
You will implement the command chunk to divide a large file (filename.txt) into files of 1,000 lines each. At the UNIX shell prompt, your command should accept either:
chunk [options] -f filename.txt [-p prefix] [-s suffix]
chunk [options] [-p prefix] < filename.txt
[options] in square brackets indicates that the command recognizes both excluding [options], or including options. The options modifies the size of output of the files, as follows.
-l line_count
---- Creates smaller files of line_count lines in length (instead of the default of 1,000 lines).
-w word_count
---- Creates smaller files of line_count lines in length (instead of the default of 1,000 lines).
-c character_count
---- Creates smaller files of line_count lines in length (instead of the default of 1,000 lines).
.
The chunk command will give each output file it creates the name prefix with a extension or suffix tacked to the end that indicates its order. By default, the chunk command should use 2 character alphabetical suffixes:
----- aa to the first output file,
----- bb to the second output file,
proceeding through the alphabet to
----- zz for subsequent files.
If the user prefers numberic:
-s suffix
---- Creates a 2 digit character numeric suffix, with starting number indicated by the suffix, so that if suffix -is 00, then chunk will generate:
----- 00 to the first output file,
----- 01 to the second output file,
proceeding through the alphabet to
----- 01 for subsequent files.
-p prefix
---- If a prefix is not indicated, the default prefix will be x.
EXIT STATUS The chunk utility exits 0 on success, and >0 if an error occurs.
Example:
chunk -l 100 -f maria.txt -p part- -s 00
Here chunk divides file maria.txt to new files named part-00, part-01, part02, ... that are each 100 lines long, except possibly the last file that may be less than 100 lines long.
chunk -w 100 -f maria.txt -p part- -s 00
Here chunk divides file maria.txt to new files named part-00, part-01, part02, ... that are each 100 words, except possibly for the last file that may be less than 100 words long.
The join the files back together again the cat command:
cat part-00 part-01 part02 ... > maria2.txt
should generate fle maria2.txt so that it is identical to the original maria.txt.
The permissions of the output files should be the same as the permissions of the input file.
You should use try to make your program as efficient as possible.
Your program should not overwrite existing files, e.g., if there is a file part-01 in your directory already, your program should print out an error message and terminate.
Your program should be readable.
You should comment your code.
For printing out errors, you must print to stderr.
You may only use read(), write() for reading the input file, and writing to the output files. You may use other input/output functions for other things, e.g., for printing errors for example, or for debugging, you may use fprintf(), if you prefer.
You must submit the following files (i.e., all the files necessary to compile your program):
README.txt
*.c (all your .c files, you should have at least 2 .c files)
*.h (all your .h files, you should have at least 1 .h file).
Makefile
To submit the files, you will need to use the submit program. Your files need to be under a common subdirectory called "1730_program3". If the 1730_program3 subdirectory is directly under your home directory you execute the below command line while in your home directory:submit 1730_program3 cs1730
NOTE 1: you need to be LOGGED ONTO nike.cs.uga when you execute the command
NOTE 2: look at the example Makefile and program available from the scheduler page.
NOTE 3: be aware of white space in your makefiles