UNIX grep sur une seule ligne

Résolu/Fermé
gormoth - 3 mars 2010 à 15:18
 Gormoth - 4 mars 2010 à 11:59
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

2 réponses

dubcek Messages postés 18718 Date d'inscription lundi 15 janvier 2007 Statut Contributeur Dernière intervention 22 mars 2024 5 615
3 mars 2010 à 16:36
hello
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 
$ 
0
Super, ca m'a bien aidé, il a juste fallu que je modifie certaines petites info
0