I am writing a Script in which one of the functions is to search in a text file DNI or Name that the user is asked for and when he finds them he will print the whole lines.
The file has the format "DNI | Name"
2:Pepe
21:Julio
1:Marta
The buscarNombre
function works correctly for me:
function buscarNombre()
{
echo Introduce Nombre a buscar:
read nombrex
nombrex='grep "\$nombre\b" agenda.txt'
echo $nombrex
menu
}
But the function look for DNI instead of looking for and printing a DNI in particular I look for and print any DNI that contains the number that I have passed them.
function buscarDNI()
{
echo Introduce DNIx a buscar:
read DNIx
DNIx='grep "\$DNIx\b" agenda.txt'
echo $DNIx
menu
}
If for example, I tell him to look for the DNI: 2, he will print lines 2: Pepe and 21: Julito and I just want you to print 2: Pepe.
How can I improve buscarDNI
to only search for the exact ID?