Shell – Sed incremental arithmetic

arithmeticgnusedshell-scriptUbuntu

I want to change a number at the end of a string by incrementing that number by one each time I run a specific sed line.

The string looks like this:

server-port=25555

I was thinking I could run something like this sed line to do it, but it doesn't work.

sed -i 's/port=[0-9]{5}/int(&+1)/'

Best Answer

I would suggest perl instead of sed for this task:

perl -i -pe 's/(port=)(\d+)$/$1.($2+1)/e' filename
Related Question