Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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.

PLEASE POST ALL CODE WITH OUTPUT SHOWN TO DEMONSTRATE THE PROGRAM WORKS

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Databases Object Oriented Deductive Hypermedia Technologies

Authors: Kamran Parsaye, Mark Chignell, Setrag Khoshafian, Harry Wong

1st Edition

0471503452, 978-0471503453

More Books

Students also viewed these Databases questions

Question

1. Where will you recommend that she hold the focus group?

Answered: 1 week ago

Question

3. What might you have done differently

Answered: 1 week ago