Q:

in Shell, How to do arithmetic operation on a number which is part of a string?

I wanted to add 100 to the insertions, tried below, but it is adding $1 to it instead ?
#!/bin/bash
change_summary="17 files changed, 441 insertions(+), 49 deletions(-)"
lines_added="100"
echo $change_summary
echo $change_summary | awk '{ print $1 " " $2 " " $3 " " $4+$lines_added " " $5 " " $6 " " $7}'

it prints
17 files changed, 441 insertions(+), 49 deletions(-)
17 files changed, 458 insertions(+), 49 deletions(-)

I am expecting it to print 541 insertions.
is there a better way to do the same?

A:

Use an awk variable (tested with GNU awk):
 awk -v l=$lines_added '{ print $1 " " $2 " " $3 " " $4+l " " $5 " " $6 " " $7}'

or even more succinctly:
 $ echo $change_summary | awk -v l=$lines_added '{ $4 += l; print}'
 17 files changed, 541 insertions(+), 49 deletions(-)

