subodh1989
subodh1989

Reputation: 716

Storing the grep output in loop

This grep commands prints the numbers (the count of groups merged)

 grep "merged" sombe_conversion_PSTN.sh.sql.log | awk '{print $1}' | sed 's/ //g'

The Output is as follows:

1000000
41474
41543
83410
83153
83085
82861
82904
82715
41498
41319

I need to add the data from second to last row of output and store it in a variable and first element in a different variable.

for example :

var_num=1000000
sum_others=663962

How do i loop and add the variables?

Upvotes: 0

Views: 149

Answers (1)

user647772
user647772

Reputation:

Do it twice. If your list of numbers is in the file output, do

$ var_num=$(cat output | head -1)
$ sum_others=$(cat output | sed '1d' | awk '{s += $1} END {print s}')

Upvotes: 1

Related Questions