I have a file like this:
id=1+5
id=1+9
id=25100+10
xyz=1+
abc=123456
conf_string=LMN,J,IP,25100+1,0,3,1
I would like to replace instances of x+y to the value of (x+y). That is 1+5 is replaced by 6, 25100+1 is replaced by 25001 and so on.
I was trying this with gawk by matching with a regex like /[:digit:]++[+digit:]+/
Using the following I could replace some of the instances.
gawk 'BEGIN {FS = "[=+,]"} ; /[:digit:]++[+digit:]+/ {print $1 "=" ($2 + $3)} ! /[:digit:]++[+digit:]+/ {print $0}' /tmp/1.txt
id=6
id=10
id=25110
xyz=1+
abc=123456
conf_string=LMN,J,IP,25100+1,0,3,1
I am unsure of how to match and replace (25100+1) in the above example. Ideally, I would like to extract all instances of <number> + <number>
and replace it with the sum. It will always be a sum of two numbers.