I'm new in bash scripting and need help with the following please:
The purpose of this homework is to let students write programs in bash scripting language that enable them to manipulate data in a text file similarly to a database table..
Students should understand the table structure and write the programs check_table, row_select and row_delete using bash scripting langauge.
A table consists of a text file that contains lines. The first line contains information about the
table and each of the rest of lines represents a data row.
The first line structure is as follows:
table_name:number_of_rows:number_of_fields:fieldna me1,fieldname2,filedname3 ...etc
- table_name is an alphanumeric string not exceeding 16 characters and does not include the
column character : nor the space character . It must be the same as the file name.
- number_of_rows is a integer with value less than 1000.
- number_of_fields is a integer with value less than 10.
- filedname is an alphanumeric string not exceeding 16 characters and not including the space nor the comma , characters.
Each data row consists of a series of fields delimited by the comma character,. Each row has
exactly the same number of fields as all other fields in the table. A field consists of a string
of alphanumeric characters, does not exceed 16 characters and does not contain the space
character nor the comma character ,.
The program checks the following in order:
- command syntax
- table exists.
- first line syntax is correct.
- tablename and fieldnames all have correct lengths.
- Table has correct number of rows.
- All rows have correct number of fields.
- table <tablename> is good
- table <tablename> has a a problem
problem description (first problem encountered)
$ check_table students_info
table students_info is good
$ check_table student_info1
table students_info has at least one problem:
Actual number of rows not equal to the one in the file header.
I know it's homework but i need some guide about this.
Write down all the tasks that need to accomplished.
How to read the header record of the "database". The line has some fields separated with a comma, and others separated with a colon. There could be a variable number of fields on the line depending upon the value of field three (value 5).
In order to do this, you should read the man page for the "read" command, paying special attention to the function of the "IFS" environment variable.
Then write a script that just reads this first line and prints each field on a separate line.
Once you have completed several of these tasks, you can start combining them into larger programs.