Question: Need help implementing these UNIX commands using C programming , please show test output to demonstrate that code works. You will implement the command chunk

Need help implementing these UNIX commands using C programming, please show test output to demonstrate that code works.

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 world_count lines in length (instead of the default of 1,000 lines). -c character_count ---- Creates smaller files of character_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 an 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, ----- ab to the second output file, proceeding through the alphabet to ----- ac ..., az, ba, bb, bc, ... bz, ca, cb, ... cz, ... ----- zz for subsequent files.

If the user prefers numeric:

-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 (numberic) to ----- 99 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, part-02, ... part-?? 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, part-02, ... part-?? that are each 100 words, except possibly for the last file that may be less than 100 words long.

Other Requirements:

The join the files back together again the cat command:

cat part-00 part-01 part-02 ... > maria2.txt

should generate file 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.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!