Faire la somme du STDOUT

Pour additionner tous les nombres envoyés par la sortie standard, par exemple :

~: seq 1 5 
1
2
3
4
5

Vous pouvez utiliser la commande awk :

~: seq 1 5 | awk '{ total+=$1 } END { print total }'
15

Poster un nouveau commentaire

Le contenu de ce champ ne sera pas montré publiquement.
  • You can use BBCode tags in the text.
  • Les lignes et les paragraphes vont à la ligne automatiquement.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".

Plus d'informations sur les options de formatage