Increment version text stored in a bash script file

Solution 1:

awk -F'[ .]' '/^echo version/ {print $1,$2,$3"."$4"."$5+1}' ~/.bashrc

Output:

echo version 1.0.2

-F'[ .]': field separator(s) blank and dot

/^echo version/: search for line starting (^) with echo version

print $1,$2: print strings separated by a blank

$5+1: increment string/value by 1

Solution 2:

perl to the rescue

$ cat file
echo version 1.0.1
$ perl -i -pe 's/echo version \d+\.\d+\.\K(\d+)/ $1+1 /e' file
$ cat file
echo version 1.0.2