Somme dans un fichier
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
-
Contributeurhello
$ 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 -
Contributeuret aussi
$ sed '2,$s/$/+/;$s/$/p/' fichier | dc
1111 -
Contributeuret et aussi
$ echo $(($(sed '$!s/$/+/' fichier)))
1111