I am doing a shell script to be able to read some records from a file, then ask the user to input a name. The script should then be able to search the records and only print out the requested record.

I have figured out how to print the records but I do not know how to search and print only the requested data.

#5recordPrint
function print
{
clear
echo "Name, Position, Department, Salary"
echo "========================================"
awk 'BEGIN{FS=","; RS="\n"} {printf "%s, %s, %s, %s\n", $1, $2, $3, $4}' data.txt

}

thanks that helped alot

by the way, if i want to say delete a line of record, can i use the
tr -d?? Because I have been searching the Bash commands and havent found and delete command for shell scripts:(

ok so I tried this on my data file which contains records:
Name, Dept, Job, Pay
John, Finance, Accountant, $2000

read -p "Enter name of Employee to Remove?: " remEmp
tr -d "grep -n -i $remEmp $dataFile" >> $dataFile

Am I using the tr -d wrongly? Or do I just have some syntax errors? coz the script doesnt seem to work. I need to delete a whole line of record and the user just needs to enter a search parameter.

Yes, you're using tr wrongly.
tr just translates (or deletes) characters. Not lines, or things matching lines.

You could try

grep -v $remEmp $dataFile > temp
mv temp $dataFile

which finds everything EXCEPT (that's -v, invert) what matches the thing you want to remove.

This question has already been answered. Start a new discussion instead.