Assignment

The lines of the text file productratings.txt1 take the following format:

<product-id> <member-id> <rating> <status> <creation> <last-modified> <type> <review-id>
    

Each line contains information about a certain product: score given to the product by a certain user, initial and last date when user gave his score, indication whether score may be made visible to other users, ... You are asked to compose a series of substitution commands that successively perform the following tasks in the text editor vi or vim. Try to use as few commands and as few characters per command as possible. Comment lines should not be affected by the substition commands. All changes should occur in succession To check for correctness you can use the files WHO.$$i$$.txt (1 ≤ $$i$$ ≤ 8), that contain the content generated right after the $$i$$-th command was executed.

  1. Mark all plain text lines (i.e. lines that are not formatted according to the field template described above) as comment lines by placing a hash (#) symbol before those lines. These comment lines should not be affected by the following substitution commands. (productratings.1.txt2)

  2. Remove data from the last column. (productratings.2.txt3)

  3. Copy the value from the column <creation> to the column <last-modified> on all lines that have an empty value in the <last-modified> column. (productratings.3.txt4)

  4. Replace all high ratings (4 or 5) by OK! (productratings.4.txt5)

  5. Replace all other ratings by NOK. (productratings.5.txt6)

  6. Change the date format from yyyy/mm/dd into dd/mm/yyyy. (productratings.6.txt7)

  7. Search all lines that have an product-id starting with a digit between 1 and 5, and that have been scored only once (creation date equal to date last modified). Mark those lines by placing an asterisk (*) in front of them. (productratings.7.txt8)

  8. Re-organize the file in the following way:

    <product-id> <member-id> <rating> <status> <creation> <last-modified> <type>
            

    should be converted into (productratings.8.txt9)

    <product-id>A <member-id> <rating>
    <product-id>B <creation> <last-modified>
    <product-id>C <status> <type>
    <empty line>
            

Guidelines for submitting a solution

Carefully follow the instructions below when submitting a solution: