Question: PROGRAM DESCRIPTION: In this assignment, you will write sed and gawk commands to accomplish certain requested functionality. Given the many powerful features of sed and



PROGRAM DESCRIPTION: In this assignment, you will write sed and gawk commands to accomplish certain requested functionality. Given the many powerful features of sed and gawk, you are provided with links to manuals and tutorials for sed and gawk to assist you in completing this assignment. Using sed a) Consider the following file called dates.txt containing some dates in US format, some of them palindromes (1.e., words that read the same backwards and forwards) and some not: 02/02/2020 03/02/2030 12/02/2021 06/19/1960 01/10/2010 03/07/2100 Write a one-line sed command that prints out only the lines containing date palindromes so that after running the appropriate sed command, the following would be output to the terminal: 02/02/2020 03/02/2030 12/02/2021 You may write the sed command-line in the space provided below and ensure that this Word document (with your solutions) is submitted to Canvas. Answer: b) Consider the following file called letter.txt containing a company letter: ABC Corp 1234 7 Oaks Lane Denton, TX 76509-4321 (682) 543-7890 Y February 7th, 2020 Ms. Sue Jones 1515 Mockingbird Lane Apartment @701 Denton; TX 76509 Dear Mrs. Jones, This letter is to inform you that you have won the super coder contest. To Claim your winnings, you may visit our office or call our claim hotline (654) 817-4321, Mention your claim number @687. Sincerely, Lois Lane Write a complete sed script called minori.sed that will modify the letter in the following ways: 1. Preprocessing: a. Change the area code of the phone number in the heading to 800. b. Remove the parentheses from each phone number. c. Add a dash between the area code and the rest of the phone number. (.e. 789 123-4567 would become 789-123-4567) d. Change the zip+4 code in the heading from 4321 to 1234. The zip+4 is the last 4 digits of the zip code after the dash. e. Change Lois' last name from Lane to Kent, since she became married. f. Change Lane in the addresses to Ln. 2. Transposition (1.e., rearrange the order of individual characters): a. Swap the area code and exchange for the phone number in the body of the letter. 3. Substitution (i.e., replace characters by other characters): a. Substitute '#' for '@' to correct a type where '@' were used instead of '# and change to, to correct the typos in the addresses. 4. Append extra data: a. Append a p.s. clause after the signature (the end of the letter). It should read p.s. your winnings must be claimed by February 29th. In this file, for example, my sed script should print the following: $ sed -r -f minori.sed letter.txt ABC Corp 1234 7 Oaks Ln Denton, TX 76509-1234 800-543-7890 February 7th, 2020 Ms. Sue Jones 1515 Mockingbird In Apartment #701 Denton, TX 76509 Dear Mrs. Jones, This letter is to inform you that you have won the super coder contest. To Claim your winnings, you may visit our office or call our claim hotline 817-654-4321. Mention your claim number +687. Sincerely, Lois Kent p.s. your winnings must be claimed by February 29th. This sed script file will be submitted to Canvas. Using gawk a) Consider a file containing grade test grades for students called grades.txt file: Last, First, A/I, Testi, Test2, Test3 Smith, John, A, 90, 100,99 Ballard, Sue, I, 15,,50 Clark, Sally, A, 100, 50, Koen, Jack, I, 90, 100,99 Ball, Lucy, A, 100, 100, 100 Bently, Mark, A, 100,,100 The file is comma delimited. The first line is a header. The records contain Last Name. First Name, Active/Inactive file and several test scores. Ignore the heading line. For each Active student calculate their average grade for each student printing out the Students First Name followed by Last Name and average score. Display a heading at the beginning with a name for the report and headings for the columns of Name and Average. After all students have been processed display the number of active students and the average class test score. Format the output so that only 1 digit after the decimal point is shown and the averages scores line up on the decimal points. In this file, for example, the gawk program should print the following: $ gawk -f minori.gawk grades.txt Student Average Test Scores Name Average John Smith 96.3 Sally Clark 50.0 Lucy Ball 100.0 Mark Bently 66.7 4 Students with average score of 78.2 Formatting properly in columns as shown is required. This gawk program file will be submitted to Canvas. b) Consider the following file called gasoline.txt: Station Regular Premium Exxon, 2.39,2.50 Mobile, 2.19, 2.25 Shell, 3.19, 3.29 CircleK, 3.01, 3.15 QT, 2.11,2.15 Each field in this file is separated by a comma and each record is separated by a newline character. For this file, you will write a one-line gawk command-line to filter records where the premium price is less than $3 and the premium price difference between regular and premium is less than 10 cents. Specifically, you will print out only the station name and the price for premium. Add a $ in front of the price. You may write the gawk command-line in the space provided below and ensure that this Word document (with your solutions) is submitted to Canvas. Answer: REQUIREMENTS: PROGRAM DESCRIPTION: In this assignment, you will write sed and gawk commands to accomplish certain requested functionality. Given the many powerful features of sed and gawk, you are provided with links to manuals and tutorials for sed and gawk to assist you in completing this assignment. Using sed a) Consider the following file called dates.txt containing some dates in US format, some of them palindromes (1.e., words that read the same backwards and forwards) and some not: 02/02/2020 03/02/2030 12/02/2021 06/19/1960 01/10/2010 03/07/2100 Write a one-line sed command that prints out only the lines containing date palindromes so that after running the appropriate sed command, the following would be output to the terminal: 02/02/2020 03/02/2030 12/02/2021 You may write the sed command-line in the space provided below and ensure that this Word document (with your solutions) is submitted to Canvas. Answer: b) Consider the following file called letter.txt containing a company letter: ABC Corp 1234 7 Oaks Lane Denton, TX 76509-4321 (682) 543-7890 Y February 7th, 2020 Ms. Sue Jones 1515 Mockingbird Lane Apartment @701 Denton; TX 76509 Dear Mrs. Jones, This letter is to inform you that you have won the super coder contest. To Claim your winnings, you may visit our office or call our claim hotline (654) 817-4321, Mention your claim number @687. Sincerely, Lois Lane Write a complete sed script called minori.sed that will modify the letter in the following ways: 1. Preprocessing: a. Change the area code of the phone number in the heading to 800. b. Remove the parentheses from each phone number. c. Add a dash between the area code and the rest of the phone number. (.e. 789 123-4567 would become 789-123-4567) d. Change the zip+4 code in the heading from 4321 to 1234. The zip+4 is the last 4 digits of the zip code after the dash. e. Change Lois' last name from Lane to Kent, since she became married. f. Change Lane in the addresses to Ln. 2. Transposition (1.e., rearrange the order of individual characters): a. Swap the area code and exchange for the phone number in the body of the letter. 3. Substitution (i.e., replace characters by other characters): a. Substitute '#' for '@' to correct a type where '@' were used instead of '# and change to, to correct the typos in the addresses. 4. Append extra data: a. Append a p.s. clause after the signature (the end of the letter). It should read p.s. your winnings must be claimed by February 29th. In this file, for example, my sed script should print the following: $ sed -r -f minori.sed letter.txt ABC Corp 1234 7 Oaks Ln Denton, TX 76509-1234 800-543-7890 February 7th, 2020 Ms. Sue Jones 1515 Mockingbird In Apartment #701 Denton, TX 76509 Dear Mrs. Jones, This letter is to inform you that you have won the super coder contest. To Claim your winnings, you may visit our office or call our claim hotline 817-654-4321. Mention your claim number +687. Sincerely, Lois Kent p.s. your winnings must be claimed by February 29th. This sed script file will be submitted to Canvas. Using gawk a) Consider a file containing grade test grades for students called grades.txt file: Last, First, A/I, Testi, Test2, Test3 Smith, John, A, 90, 100,99 Ballard, Sue, I, 15,,50 Clark, Sally, A, 100, 50, Koen, Jack, I, 90, 100,99 Ball, Lucy, A, 100, 100, 100 Bently, Mark, A, 100,,100 The file is comma delimited. The first line is a header. The records contain Last Name. First Name, Active/Inactive file and several test scores. Ignore the heading line. For each Active student calculate their average grade for each student printing out the Students First Name followed by Last Name and average score. Display a heading at the beginning with a name for the report and headings for the columns of Name and Average. After all students have been processed display the number of active students and the average class test score. Format the output so that only 1 digit after the decimal point is shown and the averages scores line up on the decimal points. In this file, for example, the gawk program should print the following: $ gawk -f minori.gawk grades.txt Student Average Test Scores Name Average John Smith 96.3 Sally Clark 50.0 Lucy Ball 100.0 Mark Bently 66.7 4 Students with average score of 78.2 Formatting properly in columns as shown is required. This gawk program file will be submitted to Canvas. b) Consider the following file called gasoline.txt: Station Regular Premium Exxon, 2.39,2.50 Mobile, 2.19, 2.25 Shell, 3.19, 3.29 CircleK, 3.01, 3.15 QT, 2.11,2.15 Each field in this file is separated by a comma and each record is separated by a newline character. For this file, you will write a one-line gawk command-line to filter records where the premium price is less than $3 and the premium price difference between regular and premium is less than 10 cents. Specifically, you will print out only the station name and the price for premium. Add a $ in front of the price. You may write the gawk command-line in the space provided below and ensure that this Word document (with your solutions) is submitted to Canvas. Answer: REQUIREMENTS
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
