How to sum particular field in text file?

how to sum particular field in text file

i am having text file like

222|4000|abc
333|5000|xyz
444|6000|mno

i want sum of second field
i.e 4000+5000+6000

can u pls help

awk -F'|' '{s+=$2}END{print s}' infile
total=0
while IFS="|" read a b c
do
 total=$(( total+b ))
done < "file"
echo $total

The following way we can achieve your requirement

sample file:

1 2
4 5
7 8

required output:

1+2 = 3
4+5 = 9
7+8 = 15

Sample Code:

cut -d ' ' -f 1,2 one | sed -n '1,$p' | sed 's/[ ]/+/'| bc