Question

Create shell scripts, each in its own .sh file. Please include a shebang line at the...

Create shell scripts, each in its own .sh file. Please include a shebang line at the top of the script as well as appropriate comments through out. Write a script that uses sed to replace all instances of the name "Lizzy" with "Elizabeth" in a text file. Save the updated text in a new file named after the original text file with "-formal" appended before the file extension, e.g. old.txt -> old-formal.txt. Test this script on the data-shell/writing/data text files.

Note: "Okay substitution, but this script will only process a file named old.txt. "old.txt" in the problem description is only an example (e.g. == "for example"). Your script should process any file(s) given as arguments."

Homework Answers

Answer #1
#the command used to create a file named 'old' is as follows
$vi old.sh
#then type 'i' for entering into insert mode(to type the commands into the file)
#in old.sh file 
!bin/bash #Shebang line
filename=$1 #store the given file name as argument into variable filename
#below line is command to replace/substitute Elizabeth in the place of Lizzy in the given file
sed -i 's/Lizzy/Elizabeth/g' $filename 
#now press 'esc' and !wq to save and exit the file
#run the script using below command
$/.old.sh file.txt > file-format.txt #here file.txt is the file on which you would like to do modification and file-format.txt is destination file to save the result
$cat file-format.txt #displays the modified file

In case of doubts, please let me know i'll assist you and please give a thumbs up for motivation.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions