Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please complete both a and b. Thank you PROGRAM DESCRIPTION: In this assignment,

ID: 3751428 • Letter: P

Question

Please complete both a and b. Thank you

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 a link to a tutorial for sed as well as gawk to assist you in completing this assignment Using sed For help using sed, you may find the tutorial http://www.grymoire.com/Unix/Sed.html or the actual sed manual https://www.gnu.org/software/sed/manual/sed.html useful a) The // character sequence is often known as C++ style or single-line comments, while the /* */character sequence is often known as C-style or multi-line comments. As an example, assume the following myprog.c file that has a mix of both C-style and C++ style comments // This is a test of how this works #include int mainO // declare some variables here int num1-4; float num2 3.5 // print the result printf'The result is %n", num1 num2); // this does it / does it work?/ return 0; Write a one-line sed command that transforms all of the C++ style (i.e., single-line comments) to the C-style (i.e., multi-line comments) so that after running the appropriate sed command, the following would be output to the terminal /* This is a test of how this works */ #include int mainO

Explanation / Answer

Answers:

a) Here we are asked to replace one pattern with other i.e. // style comments to /* ... */

General rule of using sed command is to search for a pattern and replace it with new pattern 's/<old>/<new>/' .

In below :

- #// : means that we are searching for all lines having '\' in them

- *(.*[^ ]) *$: means anything(i.e. any character) after the \ is found and is stored is ''

- #/*  */#: means replaced/new text will be of format " /* <everything after //> */

sed -e 's#// *(.*[^ ]) *$#/*  */#' < myprog.c

/* This is a test of how this works */

#include <stdio.h>

int main()

{

/* declare some variables here */

int num1 = 4;

float num2 - 3.5;

/* print the result */

printf("The result is %f ", num1 * num2);/* this does it */

/* does it work? */

return 0;

}

b)

1. sed -e '/^412/d' phone.txt

Deletes the number starting with 412

2. sed -e 's/([0-9])([0-9])([0-9]) .*/() /g' phone.txt

Reverse firsrt 3 digits of all number and add (***) formatting to them.

Hope this helps

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote