UNIX grep sur une seule ligne
Résolu
Bonjour,
Je cherche à faire un reporting intelligent d'un fichier texte présent sous la forme :
ville:Monaco
[INFO] BLABLA
[ERROR] BLABLA
ville:Dubaï
[INFO] BLABLA
[ERROR] BLABLA
[ERROR] BLABLA
[ERROR] BLABLA
ville:Djibouti
[INFO] BLABLA
[ERROR] BLABLA
et donc qui va me permettre de me compter le nombre d'erreurs en fonction du nom de la ville ! (tout un programme)
j'ai fait ca mais ca ne match pas du tout
for ville in `cat test.txt | grep ville | cut -d ':' -f 2`
do
echo "$host"
while read line
do
AVERAGE="`cat $line | grep "ERROR" | awk '{print $4}'`"
if [ "$AVERAGE" = "[ERROR]" ]
then
COUNT=$((++COUNT))
echo "$COUNT"
fi
done < test.txt
echo "$COUNT"
done
echo "$AVERAGE"
le echo "$AVERAGE" me donne la liste de tout les [ERROR] et ne prend pas le grep sur la ligne en cours de lecture, si quelqu'un aurait déjà une sytaxe pour ca
Je cherche à faire un reporting intelligent d'un fichier texte présent sous la forme :
ville:Monaco
[INFO] BLABLA
[ERROR] BLABLA
ville:Dubaï
[INFO] BLABLA
[ERROR] BLABLA
[ERROR] BLABLA
[ERROR] BLABLA
ville:Djibouti
[INFO] BLABLA
[ERROR] BLABLA
et donc qui va me permettre de me compter le nombre d'erreurs en fonction du nom de la ville ! (tout un programme)
j'ai fait ca mais ca ne match pas du tout
for ville in `cat test.txt | grep ville | cut -d ':' -f 2`
do
echo "$host"
while read line
do
AVERAGE="`cat $line | grep "ERROR" | awk '{print $4}'`"
if [ "$AVERAGE" = "[ERROR]" ]
then
COUNT=$((++COUNT))
echo "$COUNT"
fi
done < test.txt
echo "$COUNT"
done
echo "$AVERAGE"
le echo "$AVERAGE" me donne la liste de tout les [ERROR] et ne prend pas le grep sur la ligne en cours de lecture, si quelqu'un aurait déjà une sytaxe pour ca
Configuration: Windows XP / Firefox 3.0.10
2 réponses
-
Contributeurhello
quelque chose comme ça ?$ awk '/ville/ {split($0,v,":");err[v[2]]=0} ; /ERROR/ {err[v[2]]++;e[i++]=$0} ; END{for (n in err)print n,err[n];for(n in e)print e[n]}' fichier Monaco 1 Djibouti 1 Dubaï 3 [ERROR] BLABLA [ERROR] BLABLA [ERROR] BLABLA [ERROR] BLABLA [ERROR] BLABLA $ -
Super, ca m'a bien aidé, il a juste fallu que je modifie certaines petites info