I have a textfile details.txt that have details of itemId,itemName,itemQuantity
details.txt
1,egg,20
2,meat,40
firstly I will request the user to input the item name and if the input of the item name matches with the item name found in text file , it will print out the quantity for the item.
e.g Enter item name:egg
output
Quantity
20
below is what I have but it's not working as I don't know how to achieve my expected output. Please advise thanks
#!/bin/bash
fileName="details.txt"
read -p "Enter item name" itemName
if grep -q $itemName $fileName; then
echo "Quantity"
awk '{print $4}' $fileName
else
echo "No Record Found"
fi
my output
Quantity
20
40