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

Create a directory ~/UnixCourse/scriptAsst. Turn the two-line version, above, of

ID: 3712656 • Letter: C

Question

Create a directory ~/UnixCourse/scriptAsst.

Turn the two-line version, above, of the substitution commands into a shell script, subst1 taking three command-line parameters:

the string to be replaced

the string with which to replace it

the name of the file in which to make the substitution

For example,

should print the line:

having replaced all occurrences of “is” in the file myFile.txt by “are”, leaving the original file as myFile.txt.bak.

Similarly,

should remove (replace by the empty string) all occurrences of “o” in the file aardvark.dat, leaving the original file as aardvark.dat.bak. The output of the final statement should be:

Explanation / Answer

You can create the directory by using the following command:
cd ~ && mkdir UnixCourse && cd UnixCourse && mkdir scriptAsst

The bashrc which takes 3 argument to convert the data in the file is as follows:

# Code to take argument values and keep it
a=$1
b=$2
c=$3
# Code to read the data from the filename
filedata=$(cat $3)
# Code to replace the data from the string
filedata=${filedata//$a/$b}
# Code to write the modified data back in the file
echo $filedata > $c

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