# cat file ello barbaz?cache_version=4fooooo bye # sed -i -r 's/(.*)(?cache_version=)([0-9]+)(.*)/echo "12$((3+1))4"/ge' file # cat file ello barbaz?cache_version=5fooooo bye # 传递外部变量 #cache="cache_version=" #sed -i -r 's/(.*)(?'$cache')([0-9]+)(.*)/echo "12$((3+1))4"/ge' file # cat file ello barbaz?cache_version=6fooooo bye
参考:
https://stackoverflow.com/questions/14348432/how-to-find-replace-and-increment-a-matched-number-with-sed-awk