Problème grep
Résolu
tlep
Messages postés
596
Date d'inscription
Statut
Membre
Dernière intervention
-
tlep Messages postés 596 Date d'inscription Statut Membre Dernière intervention -
tlep Messages postés 596 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
j'ai un souci avec grep, qui ne trouve pas un motif existant :
toto="1 * * * * /home/thierry/cron.sh" && grep "$toto" /home/crontabs/site/spool/local/formation/thierry
Sachant que /home/crontabs/site/spool/local/formation/thierry contient bien la ligne "1 * * * * /home/thierry/cron.sh".
Par contre si je fais
toto=" * * * * /home/thierry/cron.sh" && grep "$toto" /home/crontabs/site/spool/local/formation/thierry
il me trouve bien :
1 * * * * /home/thierry/cron.sh
:-()
j'ai un souci avec grep, qui ne trouve pas un motif existant :
toto="1 * * * * /home/thierry/cron.sh" && grep "$toto" /home/crontabs/site/spool/local/formation/thierry
Sachant que /home/crontabs/site/spool/local/formation/thierry contient bien la ligne "1 * * * * /home/thierry/cron.sh".
Par contre si je fais
toto=" * * * * /home/thierry/cron.sh" && grep "$toto" /home/crontabs/site/spool/local/formation/thierry
il me trouve bien :
1 * * * * /home/thierry/cron.sh
:-()
A voir également:
- Problème grep
- Grep recursif - Forum Linux / Unix
- Grep récursif - Forum Programmation
- Find grep - Forum Shell
- Commande grep - Forum Linux / Unix
- Commande grep ✓ - Forum Ubuntu
13 réponses
Bonjour,
Déjà, vérifie ta variable toto :
echo $toto
Il se peut que tes astérisques soient interprétées dans le cas où des fichiers existent dans le répertoire où tu as affecté la variable toto.
Bonne investigation,
c-moi
Déjà, vérifie ta variable toto :
echo $toto
Il se peut que tes astérisques soient interprétées dans le cas où des fichiers existent dans le répertoire où tu as affecté la variable toto.
Bonne investigation,
c-moi
qu'affiche :
toto="1 * * * * /home/thierry/cron.sh" ; echo $?
toto="* * * * /home/thierry/cron.sh" : echo $?
puisque que c'est ce que teste &&
toto="1 * * * * /home/thierry/cron.sh" ; echo $?
toto="* * * * /home/thierry/cron.sh" : echo $?
puisque que c'est ce que teste &&
Salut,
toto="1 * * * * /home/thierry/cron.sh" && grep "${toto}" /home/crontabs/site/spool/local/formation/thierry;-))
Ben nan jipicy, pour une fois c'est pas ca :
toto=" * * * * /home/thierry/cron.sh" && grep "${toto}" /home/crontabs/site/spool/local/formation/thierry
1 * * * * /home/thierry/cron.sh
toto="1 * * * * /home/thierry/cron.sh" && grep "${toto}" /home/crontabs/site/spool/local/formation/thierry
=> rien !
:-()
toto=" * * * * /home/thierry/cron.sh" && grep "${toto}" /home/crontabs/site/spool/local/formation/thierry
1 * * * * /home/thierry/cron.sh
toto="1 * * * * /home/thierry/cron.sh" && grep "${toto}" /home/crontabs/site/spool/local/formation/thierry
=> rien !
:-()
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question
et
toto="0 * * * * /home/thierry/cron.sh" && grep "${toto}" /home/crontabs/site/spool/local/formation/thierry
toto="0 * * * * /home/thierry/cron.sh" && grep "${toto}" /home/crontabs/site/spool/local/formation/thierry
J'ajoute "0 * * * * /home/thierry/cron.sh" dans /home/crontabs/site/spool/local/formation/thierry puis :
toto=" * * * * /home/thierry/cron.sh" && grep "${toto}" /home/crontabs/site/spool/local/formation/thierry
1 * * * * /home/thierry/cron.sh
0 * * * * /home/thierry/cron.sh
toto="0 * * * * /home/thierry/cron.sh" && grep "${toto}" /home/crontabs/site/spool/local/formation/thierry
=> rien !
toto=" * * * * /home/thierry/cron.sh" && grep "${toto}" /home/crontabs/site/spool/local/formation/thierry
1 * * * * /home/thierry/cron.sh
0 * * * * /home/thierry/cron.sh
toto="0 * * * * /home/thierry/cron.sh" && grep "${toto}" /home/crontabs/site/spool/local/formation/thierry
=> rien !
est-ce que c'est 1<espace> dans toto et 1<tab> dans le fichier ?
cat -v /home/crontabs/site/spool/local/formation/thierry
cat -v /home/crontabs/site/spool/local/formation/thierry
salut Thierrytte,
il suffit de faire ça
toto="1 \* \* \* \* /home/thierry/cron.sh" && grep "$toto" /home/crontabs/site/spool/local/formation/thierry
explication:
les étoiles sont interprété comme de 0 à n fois le caractère espace et non comme des étoiles.
voila
il suffit de faire ça
toto="1 \* \* \* \* /home/thierry/cron.sh" && grep "$toto" /home/crontabs/site/spool/local/formation/thierry
explication:
les étoiles sont interprété comme de 0 à n fois le caractère espace et non comme des étoiles.
voila
Bien joué ;-)
Là ou çà se complique, c'est que le contenu de ma variable $toto est issue d'un scan de fichier, dont je cherche les occurences de chaque ligne complète dans un autre fichier
Genre :
while read Ligne;do
grep "^$Ligne$" $Spool_Local/$Hosts/$Files || echo "$Ligne: Non trouvé"
done < $Spool_Distant/$Hosts/$Files
:-)
Là ou çà se complique, c'est que le contenu de ma variable $toto est issue d'un scan de fichier, dont je cherche les occurences de chaque ligne complète dans un autre fichier
Genre :
while read Ligne;do
grep "^$Ligne$" $Spool_Local/$Hosts/$Files || echo "$Ligne: Non trouvé"
done < $Spool_Distant/$Hosts/$Files
:-)
grep "${toto//\*/\*}" fichier ca fonctionne;
Mais est-ce que je ne risque pas encore de tomber sur d'autres caractères qui posent problème à part "*", en passant en variablechaque ligne de mon fichier source ?
PS: c'est quoi cette syntaxe sur grep ? c'est la première fois que je la vois !!!
Mais est-ce que je ne risque pas encore de tomber sur d'autres caractères qui posent problème à part "*", en passant en variablechaque ligne de mon fichier source ?
PS: c'est quoi cette syntaxe sur grep ? c'est la première fois que je la vois !!!