I have this file called annuaire.txt with this records which is enter by a user using read and I want to search for a specific row $var like $nomPersonne I used if grep -q $recherche $prenomPersonne annuaire.txt
but didn't work.
Like I have a read command the user can enter just a letter of what he's looking for but only in one row in the file the row is one of those variables: $nomPersonne $prenomPersonne $numBureau $numTelephone $adresseEmail
function ajoutPersonne(){
read -p "Saisir le nom : " nomPersonne
read -p "Saisir le prénom : " prenomPersonne
read -p "Saisir le numéro de bureau : " numBureau
read -p "Saisir le numéro de téléphone : " numTelephone
read -p "Saisir votre adresse email : " adresseEmail
echo "$nomPersonne,$prenomPersonne,$numBureau,$numTelephone,$adresseEmail" >> annuaire.txt
}
function rechercherFiche(){
read -p "Rechercher : " recherche
if grep -q $recherche $prenomPersonne annuaire.txt
then
echo "$(grep -c $recherche annuaire.txt) resultats trouvés !"
grep -r $recherche annuaire.txt
else
echo "Non trouvée dans l'annuaire."
fi
}
It's in french don't mind the variables name.
AJLI,Zakaria,10,1234567890,bbb@ajli.fr
pers,perss,20,2345446675,ccc@pers.fr
potion,asterix,9,111111111,ddd@potion.fr
marmite,obelix,33,8687678576,yyy@marmite.fr