201k views
2 votes
Based on HW 6, Part II Problem 2, (or the script file "sub" on the last page of Lab6 Handout), please modify your bash/sed script "mysedprog" so that it will 1. remove the blank line(s), 2. delete the record for Nancy, and 3. substitute Jerry's record with Anna's record (Anna 9597 98). Please test it using "sed - f mysedprog mysedfile" and make sure the output is correct, and then provide your "mysedprog" below along with the output of the execution of the script:

User Despertar
by
7.0k points

1 Answer

5 votes

Final answer:

In the modified "mysedprog" bash/sed script, blank lines are removed, the record for Nancy is deleted, and the record of Jerry is replaced with Anna's record. The commands used are /^$/d, /Nancy/d, and s/Jerry.*/Anna 9597 98/ respectively. Run the script on 'mysedfile' to achieve the desired changes.

Step-by-step explanation:

To modify the bash/sed script "mysedprog" to achieve the specified tasks, you would need to add commands to delete the blank lines, remove the record for Nancy, and substitute Jerry's record with Anna's record. Below is the content of the modified script file "mysedprog":

  • /^$/d - This command removes all the blank lines.
  • /Nancy/d - This command deletes the record containing 'Nancy'.
  • s/Jerry.*/Anna 9597 98/ - This command substitutes 'Jerry's' record with 'Anna 9597 98'.

After creating your "mysedprog" script with the above commands, you can then run it on your data file by using the sed command as follows:

sed -f mysedprog mysedfile

The output will no longer contain any blank lines, the record for Nancy will be removed, and Jerry's record will be replaced by Anna's record, as requested.

Make sure to test the script on your actual data file to ensure it works as expected.

User Qerim Shahini
by
8.2k points