Awk : problème avec printf

Fermé
paille1962 Messages postés 2 Date d'inscription lundi 14 janvier 2013 Statut Membre Dernière intervention 14 janvier 2013 - 14 janv. 2013 à 17:04
dubcek Messages postés 18753 Date d'inscription lundi 15 janvier 2007 Statut Contributeur Dernière intervention 7 novembre 2024 - 15 janv. 2013 à 09:40
Bonjour,

j'ai un code d'erreur sur l'affichage de resultats avec le printf

BEGIN { FS=","
#OFMT="%.2f"

print "-----HANDOVER INTER MSC----- \n"," Date Heure Target MSC Succ_Inter_MSC_inc Succ_Inter_MSC_out\n"
}

$7+$15) > 0 {
printf " %14s %12s %12.2f %.2f\n", "20" substr($1,1,2) "-" substr($1,3,2) " " substr($1,7,2) ":" substr($1,9,2) ,
$2 , (($9+$17) / ($7+$15)) *100
{ if (($3 + $19) > 0) {printf ("%.2f\n", ((($5+$21) / ($3+$19)) *100))} else { printf("%.2f\n",0) }}
}

# cela me sert à mettre un zéro dans ce calcul afin d'éviter de faire une division par 0
{ if (($3 + $19) > 0) {printf ("%.2f\n", ((($5+$21) / ($3+$19)) *100))} else { printf("%.2f\n",0) }}

en lancant gawk -f nbrmsclst_kpi.awk NBRMSCLST.data

j'obient l'erreur suivante

gawk: nbrmsclst_kpi.awk:7: (FILENAME=NBRMSCLST.data FNR=1) fatal : pas assez d'arguments pour satisfaire la chaîne de formatage
' %14s %12s %12.2f %.2f
'
^ à court pour celui-ci

merci pour votre support

4 réponses

Utilisateur anonyme
14 janv. 2013 à 17:28
salut,


printf " %14s %1
etc

Il manque des parenthèses
0
paille1962 Messages postés 2 Date d'inscription lundi 14 janvier 2013 Statut Membre Dernière intervention 14 janvier 2013
14 janv. 2013 à 18:00
j'ai refait avec des paranthèses , c'est pire :-(
BEGIN { FS=","
#OFMT="%.2f"

print "-----HANDOVER INTER MSC----- \n"," Date Heure Target MSC Succ_Inter_MSC_inc Succ_Inter_MSC_out\n"
}

($7+$15) > 0 {
printf (" %14s %12s %12.2f %.2f\n", "20" substr($1,1,2) "-" substr($1,3,2) " " substr($1,7,2) ":" substr($1,9,2) ,
$2 , (($9+$17) / ($7+$15)) *100 ,
{ if (($3 + $19) > 0)
{printf ("%.2f\n", ((($5+$21) / ($3+$19)) *100))}
else
{ printf("%.2f\n",0)}
)
}
}

le fichier que je traite à la forme suivante

1212310700134,CHAMBNG,13,1,13,1,9,1,8,1,5,1,5,1,33,1,28,1,8,1,8,1,0,1,0,1,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1,14,1,9,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1
1212310700134,VELIZNG,0,1,0,1,0,1,0,1,0,1,0,1,1,1,0,1,0,1,0,1,0,1,0,1,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1
1212310700134,LYPRENG,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1
1212310700134,MONANG,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1
1212310700134,FMBEZNG,0,1,0,1,0,1,0,1,0,1,0,1,36,1,34,1,0,1,0,1,0,1,0,1,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1
1212310700134,FMONTNG,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1
1212310700134,ARGENBC,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,0,0,0,1,0,1,0,1,0,1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0,1,0,1,0,1,0,1,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1
1212310700134,AMIENNG,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1
1212310700134,LYONNG,39,1,39,1,12,1,12,1,6,1,6,1,72,1,69,1,25,1,25,1,0,1,0,1,0,0,0,0,2,1,2,1,0,1,0,1,0,1,0,1,3,1,2,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1
0
Utilisateur anonyme
14 janv. 2013 à 18:32
Tu fais des printf dans un printf ?

Avec des conditions entre accolades ?

Tu devrais utiliser un opérateur ternaire.
test ? alors : sinon


Par soucis de lisibilité, tu devrais affecter des variables avec les valeurs que tu veux afficher, plutôt que d'afficher les calculs.
0
dubcek Messages postés 18753 Date d'inscription lundi 15 janvier 2007 Statut Contributeur Dernière intervention 7 novembre 2024 5 619
Modifié par dubcek le 15/01/2013 à 09:42
hello
il manque une valeur, le printf en veut 4, il y en a 3
printf " %14s %12s %12.2f %.2f\n"   
, "20" substr($1,1,2) "-" substr($1,3,2) " " substr($1,7,2) ":" substr($1,9,2) 
, $2  
, (($9+$17) / ($7+$15)) *100 
0