Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2012

    Unanswered: Help with Bash script


    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.

    Table structure
    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 ‘,’.

    students_info:3:5:std_1st_name,std_last_name,year_ of_birth,sex,program

    syntax: check_table <table_name>

    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.

    Thanks in advance.

  2. #2
    Join Date
    Jun 2009
    Lisboa, Portugal

    What kind of help/guide do you need?
    If it is homework, that must be done by you or your team... here you can take some doubts about it...


  3. #3
    Join Date
    Sep 2009
    Provided Answers: 1
    Write down all the tasks that need to accomplished.
    First task:
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts