Retourner au contenu associé (entrée de forum : Tableau en bash shell)
Posté par BAud (site web personnel) le 20 mars 2007 à 08:08. En réponse au message Tableau en bash shell. Évalué à 3.
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
[^] # Re: awk
Posté par BAud (site web personnel) . En réponse au message Tableau en bash shell. Évalué à 3.
et http://robert.wsi.edu.pl/awk/start.html devrait être un peu plus complet pour utiliser gawk
sinon j'ai modifié ton fichier en entrée en l'appelant tableau.txt pour enlever les % et les . qui ne sont généralement pas bien gérés en bash (ni en gawk...), en multipliant par 10 (ça donne des pour mille au lieu de % quoi...)
le résultat :
beginning
user=toto total1=4 nb1=7 total2=17 val1=0,571429 val2=2,42857 nb_user=1
user=tata total1=6 nb1=1 total2=0 val1=6 val2=0 nb_user=2
user=bibi total1=6 nb1=5 total2=4 val1=1,2 val2=0,8 nb_user=3
user=lolo total1=12 nb1=2 total2=10 val1=6 val2=5 nb_user=4
user=lola total1=3 nb1=4 total2=3 val1=0,75 val2=0,75 nb_user=5
nb_user=5
gawk 'BEGIN { nb_user=0 ; user_curr="unknown" ; total1=0 ; total2=0 ; nb1=0 ; } \
( 1ドル!=user_curr ) { \
if (nb_user > 0) { \
print "user=" user_curr " total1=" total1 " nb1=" nb1 " total2=" total2 " val1=" total1 * 1.0 / nb1 " val2=" total2 * 1.0 / nb1 " nb_user=" nb_user ; \
} else { \
print "beginning" ; \
} \
user_curr=1ドル ; \
nb_user++; \
total1=2ドル ; \
total2=3ドル; \
nb1=0; \
}\
( 1ドル==user_curr ) { \
total1 +=2ドル ; total2 +=3ドル ; nb1++; \
} \
END { \
print "user=" user_curr " total1=" total1 " nb1=" nb1 " total2=" total2 " val1=" total1 * 1.0 / nb1 " val2=" total2 * 1.0 / nb1 " nb_user=" nb_user ; \
print "nb_user=" nb_user ; }' tableau.txt
(dommage l'indentation ne passe pas du tout /o\