read -p "Please enter ID: " staffID
id=$(grep -w "$staffID" record | cut -d ":" -f1 | sort -u );
echo $id
I have some issues with trying to grep the correct value from a file.
The following is stored in the record file.
12:Griffin:Peter:13:14:16
14:Griffin:Meg:19:19:10
10:Griffin:Loi:19:20:20
130:Griffin:Stewie:19:19:19
13:Wayne:Bruce:19:20:2
My first column stores the id which is always unique and is what I am looking for in grep. With the code above, I only want to find the unique ID which is entered by a user and is displayed on screen but my echo produces a blank value if I enter an ID of 13 when it should produce 13 obviously. Any ideas which would solve this?
see comments in codes
Note
I don’t know the exact requirement, but I suggest that before do grep, check user input, if they inputted a valid id
([0-9]+)maybe? Because user could input.*