regex - Vim search and replace, adding a constant -
i know long shot, have huge text file , need add given number other numbers matching criteria.
eg.
identifying text 1.1200 identifying text 1.1400
and i'd transform (by adding 1.15) to
identifying text 2.2700 identifying text 2.2900
normally i'd in python, it's on windows machine can't install many things. i've got vim though :)
here simplification , fix on hobbs' solution:
:%s/identifying text \zs\d\+\(.\d\+\)\=/\=(1.15+str2float(submatch(0)))/
thanks \zs
, there no need recall leading text. str2float()
single addition done on whole number (in other words, 1.15 + 2.87 give expected result, 4.02, , not 3.102).
of course solution requires recent version of vim (7.3?)
Comments
Post a Comment