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

Let there be a musician database, “music.txt”. It is a text file, where each rec

ID: 3760662 • Letter: L

Question

Let there be a musician database, “music.txt”. It is a text file, where each record includes the fields of artist full name, CD title, date of sale, and price of the CD. Following is a sample of the musician database:

Seamus McGuire:The Wishing Tree:09-14-2000:14.95

Pat Kilbride:Loose Cannon:07-02-2000:15.95

Kevin Crawford:Seasons of Mists:06-23-2000:16.95

Prince:Purple Rain:01-01-1995:3.95

Meat Loaf:Bat out of Jell:03-03-1980:11.95

Eddie Money:Two Tickets:09-04-1979:8.98

You are asked to write a shell script that:

(1) asks for artist's name(either first or last) from user, and

(2) displays artist's record where all :'s are substituted with a pair of *'s.

Explanation / Answer

#!/bin/sh
rm temp 2> /dev/null   #Remove a temporary file if exists
echo "Enter the artist name: "   #Read the artist name.
read artist
grep $artist music.txt >> temp   #Copies the string containing the name to file temp
sed -i -e 's/:/**/g' temp   #Replacing the : with **
echo $(<temp)           #Displaying the temp file.
rm temp                   #Removing the temp file.