Question: Write a script called 07-listWithLineNumbers that does the following: i. Takes as its single parameter the path to, and name of a file. ii. Outputs

Write a script called 07-listWithLineNumbers that does the following:

i. Takes as its single parameter the path to, and name of a file.

ii. Outputs the necessary error/usage information if a file doesnt exist, is a directory (instead of a file), or if more than one parameter is provided. To do this, follow the pattern used in earlier questions and the USAGE message shown above.

iii. Inside the script, use the cat command and a for line in construct to display the lines in the specified file, preceding each line with the line number and a colon (:). Put the whole line inside single quotes. (See the examples below.)

iv. Do not use the cat flag that would do this trivially; rather, keep track of which line you are on inside the for loop, and have your code generate and display the line numbers.

v. You may need to set the IFS (Input Field Separator) variable using a line similar to eval IFS=$ so the loop splits the lines up properly.

vi. You should also consider backing up the current value of the IFS variable before changing it with the eval statement (see above) by doing something like the following: IFSBAK=$IFS

vii. You should test how your program works with the default IFS value, (for the sake of instruction), and then set it to use your newly specified IFS. Your script should set the IFS value back to its default before exiting. Sample input file (~turk/NetworkingClass/people):

Charlie Smith 122

Sally Smith113

Hank Parker 114

Jane Bailey121

Bill Williams 100

input: $ 07-listWithLineNumbers ~turk/NetworkingClass/people

output:

1: Charlie Smith 122

2: Sally Smith 113

3: Hank Parker 114

4: Jane Bailey 121

5: Bill Williams 100

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!