Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this assignment you will use the features of bash scripting. You are given a block file format and you need to convert it to

For this assignment you will use the features of bash scripting.
You are given a block file format and you need to convert it to a CSV format, and then sum some columns.
The format is as follows:
Each block represents 1 row in the table
Each block starts with "{" and ends with "}"
Each column is represented as a comma separated pair on its own line within the block. For example "height,5" on its own line represents a column height, with a value of 5 in that row.
The blocks do not have to contain the same columns. If a block has one column, and another block does not. The block lacking that column has an assumed value of "0" for that column.
Example block:
{
name,Otus Redding
height,6
}
{
name,Bill Darling
weight,70
}
In the above example there are two rows, and 3 columns. The first block has values in the column name and height, and the second block has values in name and weight.
height,name,weight
6,Otus Redding,0
0,Bill Darling,70
The above block would represent the table
Write a script called script7.sh that accepts 2 parameters:
$1, is the filename of the block format
$2, is a regex pattern that is to meant to match column names
You script will take the block formatted file and convert it to a csv file, as shown above. The column names should be in alphabetical order. Add an additional column to the table called result which sums up all the values in columns that match $2 in a given row.
For the example invocation:
./script7.sh exampleTable.csv ".eight"
Should write stdout
height,name,weight,result
6,Otus Redding,0,6
0,Bill Darling,70,70

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

More Books

Students also viewed these Databases questions