Somme dans un fichier
herysoa
Messages postés
9
Statut
Membre
-
dubcek Messages postés 18627 Date d'inscription Statut Contributeur Dernière intervention -
dubcek Messages postés 18627 Date d'inscription Statut Contributeur Dernière intervention -
Bonjour,
J'ai un fichier essai.txt avec comme contenu:
ab
bc
cd
ef
je voudai avoir leur somme comme som=ab+bc+cd+ef
Pourriez vous m'aider? comment puis je obtenir cette somme?
Merci d'avance.
Herysoa
J'ai un fichier essai.txt avec comme contenu:
ab
bc
cd
ef
je voudai avoir leur somme comme som=ab+bc+cd+ef
Pourriez vous m'aider? comment puis je obtenir cette somme?
Merci d'avance.
Herysoa
4 réponses
-
hello
$ cat fichier
1
10
100
1000
$ awk '{x+=$1} END {print x}' fichier
1111 -
Salut,
Juste pour le fun ;-))
$ cat plop
1
10
100
1000
$ som=$(tr '\n' '+' < plop)
$ echo "${som%+}"
1+10+100+1000
$ echo "${som%+}" | bc
1111 -
et aussi
$ sed '2,$s/$/+/;$s/$/p/' fichier | dc
1111 -
et et aussi
$ echo $(($(sed '$!s/$/+/' fichier)))
1111