Compter occurrence et addition de données

J'ai mis les fichiers, et ma demande
https://workupload.com/file/KLhkMb8

Merci :)

Voici le code utilisé (mais demande est plus evoluée que ce qu'il fait actuellement)

Bloc de code:
############################################################################################
####  SORTIE DES STATS VERS FICHIER TEXTE (nombre de tirages gagnants triés decroissant + etoiles) #####
############################################################################################
# compte combien occurence d'un même pseudo
awk '! /^[[:space:]]*$/ {print $(8)}' /Users/xxx/Desktop/KENODATA/RESULTATSHISTORIQUE.txt | sort -f |uniq -c | sort -r -n | tr -d '\n' > /Users/xxx/Desktop/KENODATA/RESULTATSTATS.txt

## Ajout du mot "CLASSEMENT : " avant les PSEUDOS
cat /Users/xxx/Desktop/KENODATA/RESULTATSTATS.txt > /Users/xxx/Desktop/KENODATA/RESULTATSTATS-tmp.txt
sed 's/^/ NOMBRE DE GRILLES GAGNANTES DES 100 DERNIERS TIRAGES: /' /Users/xxx/Desktop/KENODATA/RESULTATSTATS-tmp.txt >  /Users/xxx/Desktop/KENODATA/RESULTATSTATS-tmp1.txt
sed  "s/   /         /g"  /Users/xxx/Desktop/KENODATA/RESULTATSTATS-tmp1.txt >  /Users/xxx/Desktop/KENODATA/RESULTATSTATS-tmp2.txt
cat /Users/xxx/Desktop/KENODATA/RESULTATSTATS-tmp2.txt > /Users/xxx/Desktop/KENODATA/RESULTATSTATS.txt
rm -f /Users/xxx/Desktop/KENODATA/RESULTATSTATS-tmp.txt
rm -f /Users/xxx/Desktop/KENODATA/RESULTATSTATS-tmp1.txt
rm -f /Users/xxx/Desktop/KENODATA/RESULTATSTATS-tmp2.txt
 
A toi de voir quelle version tu préfères, la V1 ou la V2 :)

Bloc de code:
#!/bin/bash

#V1
# Donne :
#ELSIE 34 €   MICROSEB 14 €   MAGNETICO 34 €
awk '{
  split($0,ligne," : ")
  #$0 = VENDREDI 06 JUILLET 2018 - SOIR : MAGNETICO : X1 [5/6]▶ 30 € X1 -------- ★★ 30 € ★★
  #ligne[1] = VENDREDI 06 JUILLET 2018 - SOIR
  #ligne[2] = MAGNETICO
  #ligne[3] = X1 [5/6]▶ 30 € X1 -------- ★★ 30 € ★★

  joueur=ligne[2]

  #Pour ne garder que le 30 dans la partie : ★★ 30 € ★★
  gain_start=index(ligne[3],"★★")+7
  gain_end=index(ligne[3]," € ★★")
  gain=substr(ligne[3],gain_start,gain_end-gain_start)

  #Tableau contenant les gains par joueur
  tableau[joueur]=tableau[joueur]+gain
}
END {
  for (joueur in tableau)
  {
    printf "%s %s €   ",joueur,tableau[joueur]
  }
  printf "\n"
}
' RESULTATSHISTORIQUE.txt

#v2
# Donne :
#MAGNETICO   34 €
#ELSIE   34 €
#MICROSEB   14 €
awk '{
  split($0,ligne," : ")
  #$0 = VENDREDI 06 JUILLET 2018 - SOIR : MAGNETICO : X1 [5/6]▶ 30 € X1 -------- ★★ 30 € ★★
  #ligne[1] = VENDREDI 06 JUILLET 2018 - SOIR
  #ligne[2] = MAGNETICO
  #ligne[3] = X1 [5/6]▶ 30 € X1 -------- ★★ 30 € ★★

  joueur=ligne[2]

  #Pour ne garder que le 30 dans la partie : ★★ 30 € ★★
  gain_start=index(ligne[3],"★★")+7
  gain_end=index(ligne[3]," € ★★")
  gain=substr(ligne[3],gain_start,gain_end-gain_start)

  #Tableau contenant les gains par joueur
  tableau[joueur]=tableau[joueur]+gain
}
END {
  for (joueur in tableau)
  {
    printf "%s:%s\n",joueur,tableau[joueur]
  }
}
' RESULTATSHISTORIQUE.txt | sort -t':' -k2 -nr | sed "s/^\(.*\):\(.*\)$/\1   \2 €/"
 
Bonsoir,
ecatomb à l'air de te trouver une solution en commande shell.

Comme je ne connais pas assez le shell je t'ai fais un petit script applescript qui fait le job.
Il récupère le fichier "mon fichier" sur le bureau et, après traitement produit un fichier "RESULTATSTATS.txt" sur le bureau, ce fichier contient le nombre d'occurrences de chaque nom, le nom et le total des gains de ce nom.

Ne pas oublier de compléter (2 fois) le chemin du fichier mon fichier en remplaçant XXXX par ton nom utilisateur.

A toi de voir ce qui te conviens le mieux.

Bloc de code:
tell application "Finder"
    set cmd to "awk '! /^[[:space:]]*$/ {print $(8) " & "ORS" & " $(NF-2)}' "
    set liste to do shell script cmd & quoted form of "/Users/XXXXXX/Desktop/mon fichier.txt"
    set laList to {}
    set n to count paragraph of liste
    repeat with i from 1 to n
        copy paragraph i of liste to the end of laList
    end repeat
  
    set cmd to "awk '! /^[[:space:]]*$/ {print $(8)}' "
    set liste to do shell script cmd & quoted form of "/Users/XXXXX/Desktop/mon fichier.txt"
    set listnom to {}
    set n to count paragraph of liste
    repeat with i from 1 to n
        copy paragraph i of liste to the end of listnom
    end repeat
  
    set prov to {}
    set listnomuni to {}
  
    repeat
        if (count of listnom) > 0 then
            set nom to item 1 of listnom
            copy nom to the end of listnomuni
            repeat with i from 1 to count listnom
                if item i of listnom = nom then
                else
                    copy item i of listnom to the end of prov
                end if
            end repeat
          
            set listnom to prov
            set prov to {}
        else
            exit repeat
        end if
    end repeat
  
  
    repeat with j from 1 to (count of listnomuni)
        set nom to item j of listnomuni
        set gain to 0
        set NG to 0
        set NB to count of laList
      
        repeat with i from 1 to NB
          
            if item i of laList = nom then
                set NG to NG + 1
                set gain to gain + (item (i + 1) of laList)
            end if
          
        end repeat
      
        set NG to NG as string
        set nom to nom as string
        set gain to gain as string
      
        set RESULTATSTATS to open for access (path to desktop folder as text) & "RESULTATSTATS.txt" as text with write permission
        write NG & "  " & nom & "  " & gain & return to RESULTATSTATS starting at eof
        close access RESULTATSTATS
    end repeat
end tell
 
Bonjour a vous 2 :)

Je regarde (et essai de bien comprendre votre travail).
Je vais tester cet aprem, a tete reposée.

Je reviens vers vous aussitot :)

X10 merci :woot:
 
J'ai mis pas mal de commentaire dans ma version, je me sers des tableaux qui sont bien pratique sous linux ;)
 
@ symbol
En relisant tes demandes je viens de te refaire un script qui te fait le job
Il faut que tu renseignes (comme d'habitude) les adresses du fichier historique et du fichier stat (les 2 premières lignes du script)
Le fichier stat est effacé et recréé à chaque exécution du script .

Bloc de code:
tell application "Finder"
    set cheminhisto to "/Users/XXXX/Desktop/mon fichier.txt"
    set cheminstat to "/Users/XXXX/Desktop/"
    set cmd to "awk '! /^[[:space:]]*$/ {print $(8) " & "ORS" & " $(NF-2)}' "
    set liste to do shell script cmd & quoted form of cheminhisto
    set laList to {}
    set n to count paragraph of liste
    repeat with i from 1 to n
        copy paragraph i of liste to the end of laList
    end repeat
  
    set RESULTATSTATS to open for access (cheminstat as text) & "RESULTATSTATS.txt" as text with write permission
    set eof (cheminstat & "RESULTATSTATS.txt") to 0
    close access RESULTATSTATS
  
    repeat
        set nom to item 1 of laList
        set gain to 0
        set NG to 0
        set NB to count of laList
        set i to 1
        set prov to {}
      
        repeat
            if item i of laList = nom then
                set NG to NG + 1
                set gain to gain + (item (i + 1) of laList)
            else
                copy item i of laList to the end of prov
                copy item (i + 1) of laList to the end of prov
            end if
            set i to i + 2
            if i > NB - 1 then
                exit repeat
            end if
        end repeat
      
        set laList to prov
        set prov to {}
      
        set NG to NG as string
        set nom to nom as string
        set gain to gain as string
      
        set RESULTATSTATS to open for access (cheminstat as text) & "RESULTATSTATS.txt" as text with write permission
        write NG & "  " & nom & "  " & gain & return to RESULTATSTATS starting at eof
        close access RESULTATSTATS
      
        if (count of laList) < 1 then
            exit repeat
        end if
    end repeat
end tell
 
Dernière édition:
Me revoila

J'ai commencé par la V1 d'ecatombe.
- J'ai remplacé le code d'origine (posté a 18h28) par le code la V1
Du coup ca donne rien. Le script fonctionne, tout est pareil (je ne vois pas -> "ELSIE 34 € MICROSEB 14 € MAGNETICO 34 €" )
Je vois "NOMBRE DE GRILLES GAGNANTES DES 100 DERNIERS TIRAGES: 27 ELSIE 18 MAGNETICO 14 MICROSEB
"

Je me suis dit qu'il fallait pas remplacer le code d'origine (posté a 18h28), mais ajouté la V1 juste a la suite.
- J'ai ajouté a la suite du code d'origine la version V1
Du coup ca donne rien. Le script fonctionne, tout est pareil (je ne vois pas -> "ELSIE 34 € MICROSEB 14 € MAGNETICO 34 €" )
Je vois "NOMBRE DE GRILLES GAGNANTES DES 100 DERNIERS TIRAGES: 27 ELSIE 18 MAGNETICO 14 MICROSEB
"

Idem pour la V2

Il est evident que je fais mal un truc mais quoi ??? :-/
J'ai pas mis le code au bon endroit ?


Bloc de code:
############################################################################################
####  SORTIE DES STATS VERS FICHIER TEXTE (nombre de tirages gagnants triés decroissant + etoiles) #####
############################################################################################
    # compte combien occurence d'un même pseudo
    awk '! /^[[:space:]]*$/ {print $(8)}' /Users/xxx/Desktop/KENODATA/RESULTATSHISTORIQUE.txt | sort -f |uniq -c | sort -r -n | tr -d '\n' > /Users/xxx/Desktop/KENODATA/RESULTATSTATS.txt

    ## Ajout du mot "CLASSEMENT : " avant les PSEUDOS
    cat /Users/xxx/Desktop/KENODATA/RESULTATSTATS.txt > /Users/xxx/Desktop/KENODATA/RESULTATSTATS-tmp.txt
    sed 's/^/ NOMBRE DE GRILLES GAGNANTES DES 100 DERNIERS TIRAGES: /' /Users/xxx/Desktop/KENODATA/RESULTATSTATS-tmp.txt >  /Users/xxx/Desktop/KENODATA/RESULTATSTATS-tmp1.txt
    sed  "s/   /         /g"  /Users/xxx/Desktop/KENODATA/RESULTATSTATS-tmp1.txt >  /Users/xxx/Desktop/KENODATA/RESULTATSTATS-tmp2.txt
    cat /Users/xxx/Desktop/KENODATA/RESULTATSTATS-tmp2.txt > /Users/xxx/Desktop/KENODATA/RESULTATSTATS.txt
    rm -f /Users/xxx/Desktop/KENODATA/RESULTATSTATS-tmp.txt
    rm -f /Users/xxx/Desktop/KENODATA/RESULTATSTATS-tmp1.txt
    rm -f /Users/xxx/Desktop/KENODATA/RESULTATSTATS-tmp2.txt
   
#v2
# Donne :
#MAGNETICO   34 €
#ELSIE   34 €
#MICROSEB   14 €
awk '{
  split($0,ligne," : ")
  #$0 = VENDREDI 06 JUILLET 2018 - SOIR : MAGNETICO : X1 [5/6]▶ 30 € X1 -------- ★★ 30 € ★★
  #ligne[1] = VENDREDI 06 JUILLET 2018 - SOIR
  #ligne[2] = MAGNETICO
  #ligne[3] = X1 [5/6]▶ 30 € X1 -------- ★★ 30 € ★★

  joueur=ligne[2]

  #Pour ne garder que le 30 dans la partie : ★★ 30 € ★★
  gain_start=index(ligne[3],"★★")+7
  gain_end=index(ligne[3]," € ★★")
  gain=substr(ligne[3],gain_start,gain_end-gain_start)

  #Tableau contenant les gains par joueur
  tableau[joueur]=tableau[joueur]+gain
}
END {
  for (joueur in tableau)
  {
    printf "%s:%s\n",joueur,tableau[joueur]
  }
}
' RESULTATSHISTORIQUE.txt | sort -t':' -k2 -nr | sed "s/^\(.*\):\(.*\)$/\1   \2 €/"
 
Dernière édition:
Rajoute ceci à la fin, le résultat n'étant affiché qu'à l'écran dans ma version:rolleyes:
Bloc de code:
 > /Users/xxx/Desktop/KENODATA/RESULTATSTATS.txt
 
Ecatomb

Je t'ai fais une video de ce qui se passe ici (m4v)
https://workupload.com/file/F7mgsz7

Le fichier /Users/xxx/Desktop/KENODATA/RESULTATSTATS.txt reste vide, alors qu'on voit dans la video defiler dans le terminal, les PSEUDOS+GAIN €, bien que j'ai ajouté "> /Users/xxx/Desktop/KENODATA/RESULTATSTATS.txt" pour assuré une sortie vers le fichier adequat
 
Dernière édition:
Symbol

Au vu de ta vidéo, j'ai modifié le script que je te joins, il est prêt à être utilisé.
Dis-moi si cela fonctionne.

Bloc de code:
tell application "Finder"
    set cheminhisto to "/Users/xxx/Desktop/KENODATA/RESULTATSHISTORIQUE.txt"
    set cheminstat to "/Users/xxx/Desktop/KENODATA/"
    set cmd to "awk '! /^[[:space:]]*$/ {print $(8) " & "ORS" & " $(NF-2)}' "
    set liste to do shell script cmd & quoted form of cheminhisto
    set laList to {}
    set n to count paragraph of liste
    repeat with i from 1 to n
        copy paragraph i of liste to the end of laList
    end repeat
   
    set RESULTATSTATS to open for access (cheminstat as text) & "RESULTATSTATS.txt" as text with write permission
    set eof (cheminstat & "RESULTATSTATS.txt") to 0
    close access RESULTATSTATS
   
    repeat
        set nom to item 1 of laList
        set gain to 0
        set NG to 0
        set NB to count of laList
        set i to 1
        set prov to {}
       
        repeat
            if item i of laList = nom then
                set NG to NG + 1
                set gain to gain + (item (i + 1) of laList)
            else
                copy item i of laList to the end of prov
                copy item (i + 1) of laList to the end of prov
            end if
            set i to i + 2
            if i > NB - 1 then
                exit repeat
            end if
        end repeat
       
        set laList to prov
        set prov to {}
       
        set NG to NG as string
        set nom to nom as string
        set gain to gain as string
       
        set RESULTATSTATS to open for access (cheminstat as text) & "RESULTATSTATS.txt" as text with write permission
        write NG & "  " & nom & "  " & gain & return to RESULTATSTATS starting at eof
        close access RESULTATSTATS
       
        if (count of laList) < 1 then
            exit repeat
        end if
    end repeat
end tell
 
A priori, tu as sauté une ligne avant de mettre la fin. On voit bien le bon résultat dans la vidéo à 0:15

C'est ceci qu'il faut avoir :
Bloc de code:
############################################################################################
####  SORTIE DES STATS VERS FICHIER TEXTE (nombre de tirages gagnants triés decroissant + etoiles) #####
############################################################################################
    # compte combien occurence d'un même pseudo
    awk '! /^[[:space:]]*$/ {print $(8)}' /Users/xxx/Desktop/KENODATA/RESULTATSHISTORIQUE.txt | sort -f |uniq -c | sort -r -n | tr -d '\n' > /Users/xxx/Desktop/KENODATA/RESULTATSTATS.txt

    ## Ajout du mot "CLASSEMENT : " avant les PSEUDOS
    cat /Users/xxx/Desktop/KENODATA/RESULTATSTATS.txt > /Users/xxx/Desktop/KENODATA/RESULTATSTATS-tmp.txt
    sed 's/^/ NOMBRE DE GRILLES GAGNANTES DES 100 DERNIERS TIRAGES: /' /Users/xxx/Desktop/KENODATA/RESULTATSTATS-tmp.txt >  /Users/xxx/Desktop/KENODATA/RESULTATSTATS-tmp1.txt
    sed  "s/   /         /g"  /Users/xxx/Desktop/KENODATA/RESULTATSTATS-tmp1.txt >  /Users/xxx/Desktop/KENODATA/RESULTATSTATS-tmp2.txt
    cat /Users/xxx/Desktop/KENODATA/RESULTATSTATS-tmp2.txt > /Users/xxx/Desktop/KENODATA/RESULTATSTATS.txt
    rm -f /Users/xxx/Desktop/KENODATA/RESULTATSTATS-tmp.txt
    rm -f /Users/xxx/Desktop/KENODATA/RESULTATSTATS-tmp1.txt
    rm -f /Users/xxx/Desktop/KENODATA/RESULTATSTATS-tmp2.txt

awk '{
  split($0,ligne," : ")
  #$0 = VENDREDI 06 JUILLET 2018 - SOIR : MAGNETICO : X1 [5/6]▶ 30 € X1 -------- ★★ 30 € ★★
  #ligne[1] = VENDREDI 06 JUILLET 2018 - SOIR
  #ligne[2] = MAGNETICO
  #ligne[3] = X1 [5/6]▶ 30 € X1 -------- ★★ 30 € ★★

  joueur=ligne[2]

  #Pour ne garder que le 30 dans la partie : ★★ 30 € ★★
  gain_start=index(ligne[3],"★★")+7
  gain_end=index(ligne[3]," € ★★")
  gain=substr(ligne[3],gain_start,gain_end-gain_start)

  #Tableau contenant les gains par joueur
  tableau[joueur]=tableau[joueur]+gain
}
END {
  for (joueur in tableau)
  {
    printf "%s %s €   ",joueur,tableau[joueur]
  }
  printf "\n"
}
' RESULTATSHISTORIQUE.txt > /Users/xxx/Desktop/KENODATA/RESULTATSTATS.txt
 
Effectivement ca change tout

Capture_d_e_cran_2018_07_08_a_16_25_22.png
 
Maintenant que ca semble réglé, je vais jeter un oeil a la V2, et au travail de Zeltron54

J'arrive au terme de mon projet, sans votre aide,rien n'aurait été possible.
Je remercie tous les acteurs qui ont participé +macg.co pour ce lieu de partage et d'aide.

:up: :up:
 
:)
Le "> fichier" redirige ce qui devait s'afficher à l'écran (hors erreurs et messages spécifiques) dans le fichier indiqué.
S'il n'y a rien avant, cela crée un fichier vide. D'où ton problème.
 
Y'a t-il autre moyen (ou un subterfuge) pour afficher le symbole "€" car dans le forum ca ressort comme un caractere erroné ?

Capture_d_e_cran_2018_07_08_a_16_43_48.png
 
Met ceci à la place du € dans le printf, c'est le code ISO pour le € :
Bloc de code:
&#8364;
 
Chez moi ça fonctionne bien :D
Capture d’écran 2018-07-08 à 17.44.12.png
Par contre, ma page web est en UTF8. Il y a ce code dans la partie "head" du fichier html. Si je ne l'ai pas, j'obtiens ceci :
Bloc de code:
<meta charset="UTF-8">
Capture d’écran 2018-07-08 à 17.45.22.png

Exemple de page avec le codage UTF8 et les deux € qui fonctionnent :
Bloc de code:
<!DOCTYPE html>
<html lang="fr">
<head>
  <title>Titre</title>
  <meta charset="UTF-8">
</head>
<body>
  <main>
  €<br/>&#8364;
  </main>
</body>
</html>
 
Il se trouve que le texte du fichier RESULTATSTATS.txt s'affiche ici

Bloc de code:
<!-- ######################################################################################################################  -->
<!-- AFFICHAGE RESULTATSTATS au FORMAT TXT -->
<div style="overflow:hidden; overflow-x:hidden;  width:1000px; height:50px; border:#000000 0px solid;">
<object data="http://kenopronos.free.fr/RESULTATSTATS.txt" type="text/html"  width="100%" height="600%"></object>
</div>
 
Sur la page du forum : clic droit > "afficher le code source"
Cela te permettra de voir tout le code html et donc s'il y a un charset d'indiqué au tout début.

Teste quand même ceux-là :
Bloc de code:
&#x20AC;
&euro;

Sinon, tu peux aussi mettre EUR ^^

ps: si un nom a un caractère spécial, ça risque de mal s'afficher.