Fill This Form To Receive Instant Help

Help in Homework
trustpilot ratings
google ratings


Homework answers / question archive / Overview In this assignment you will write a single shell script to implement a tool to lookup, insert, and remove records in a table

Overview In this assignment you will write a single shell script to implement a tool to lookup, insert, and remove records in a table

Computer Science

Overview

In this assignment you will write a single shell script to implement a tool to lookup, insert, and remove records in a table.

The database table will be stored as one record per line in a file. Multiple tables are supported, one table per file. See the small for the required format. It is a TSV file.

While this task can be implemented more easily with multiple files, the point of this assignment is to understand how to use the shell to effectively manipulate a single file. So your database must use a single file to store the data. Secondary/temporary files can and should be used as needed.

Requirements

Write a single POSIX compliant shell script that satisfies the following requirements:

  • dbfile create [table] [field1,field2,...] create a new database table. If the table already exists then issue an error and do not create a new table.
  • dbfile add [table] [value1,value2,...] will add a single record to the table.
  • dbfile list must list the names of all the tables in the database.
  • dbfile lookup [table] [query] will show records that match the query. We want a somewhat performant database so this must only read the entire contents of the file/table once and only store one line/record at a time in memory.
  • dbfile delete [table] [query] must remove all records that match the query
  • dbfile update [table] [query] [value1,value2,...] must replace the record that matches the query with the new record.
  • The database must be stored in a directory given by the environment variable DBFILE_DATABASE if provided, otherwise it is stored in the db directory in the current working directory.
  • The query language is simple (not SQL, thank goodness). The format is "Field=Value". A record matches if it has a provided field's value matches the provided value. An example query is "Country=United States".
  • Spaces are allowed in field names and in values.
  • Do not hard code the field names in your shell script. This is part of the database table's schema. The tool must be able handle any number of columns (field names).
  • You must use commas to delimit values (so that we have a CSV file for each table). To simplify parsing, commas are not allowed in field names and values.
  • The script must define and use at lease one shell function.
  • All the code must be contained in the shell script at src/dbfile.

Hints

For this assignment we will use the ShellCheck tool for linting. It can be installed by following these instructions.

For this assignment we will be using Bats for testing. It can be installed by following these instructions.

Before you start the assignment please consider reading the manual pages for the following commands:

  • grep
  • cut
  • sed

Since the tables are stored as CSV files the VS Code extension Rainbow CSV might be useful.

Process

Please clone this repo with git clone and then in the git repo run the following command to pull the GIT submodules.

git submodule update --init --recursive

Then create the file src/dbfile, commit, ensure make test -B passes and then push your code to GitHub. Make sure your GitHub action passes as expected. Please do not modify any files in this project other than file in src.

Option 1

Low Cost Option
Download this past answer in few clicks

22.99 USD

PURCHASE SOLUTION

Already member?


Option 2

Custom new solution created by our subject matter experts

GET A QUOTE