Monday, May 25, 2015

Shell Script:- Calculate the sun of the shell output

Read the content
$ cat /tmp/ab
1. apple (70 pieces)
2. Orange (94 pieces)
3. Mango (99 pieces)
4. Pineapple (50 pieces)

Read the content and only copy save the numbers only
$ cat /tmp/ab | awk -F'(' '{print $2}' | awk '{print $1}' >/tmp/b

Add the number
$ awk '{total += $1} end { print total}' /tmp/b
313


No comments:

Post a Comment