|
|
|
|
Tester l'égalité de deux chaines en bash
Dernière réponse le 20 mai 2008 à 13:39:00 Arrakis, le 20 mai 2008 à 11:30:18Bonjour,
Je me sens un peu bete de poster pour ca mais bon ca fait une heure que je suis dessus:
J'essaye juste de tester si une chaine vaut "total"... :s
J'ai essayé :
if $a == "total"
if "$a" == "total"
if [ $a == total ]
if $a = "total"
if [ $a = "total" ]
if [ "$a" == "total" ]
if [ "$a" = "total" ]
rien a faire, je n'arrive pas a trouver la bonne synthaxe, je vous met mon fichier entier au cas ou :
#!/bin/bash
while read line
do
a=`echo $line | awk -F" " '{print $2}'`
if "$a" == "total"; then
echo $line
fi
done < fichierLog
exit 0
Merci de votre aide
Configuration: Windows XP Firefox 2.0.0.14
Salut,
[tmpfs]$ cat plop
1 totaux mauvais
2 total bon
3 totalité mauvais
4 totale mauvais
5 Total mauvais
6 toTal mauvais
7 total bon
8 tototal mauvais
[tmpfs]$ cat foo.sh
#!/bin/bash
while read line
do
a=$(echo $line | awk -F" " '{print $2}')
if [ "$a" = "total" ]; then
echo $line
fi
done < plop
exit 0
[tmpfs]$ ./foo.sh
2 total bon
7 total bon
[tmpfs]$;-))
JP - Éleveur de pingouins - Faites un geste pour l'environnement, fermez vos fenêtres et adoptez un manchot. |
Merci de ta réponse,
|
Répondre à Arrakis
|
Ton soucis doit être ailleurs alors, parce que chez moi ça marche bien : [tmpfs]$ cat plop
72762560 ./nst-009
836997952 .
836997952 total
[tmpfs]$ cat foo.sh
#!/bin/bash
while read line
do
a=$(echo $line | awk -F" " '{print $2}')
if [ "$a" = "total" ]; then
echo $line
fi
done < plop
exit 0
[tmpfs]$ ./foo.sh
836997952 total
[tmpfs]$C'est un fichier Windows le ".log" ? Si oui alors peut être regarder du côté des fins di lignes différentes entre les 2 systèmes ;-(
JP - Éleveur de pingouins - Faites un geste pour l'environnement, fermez vos fenêtres et adoptez un manchot. |
Ca marche nickel en extrayant la sous-chaine :D
|

