vim - Change all numbers in a block of text all at once -


i have file (pac file) contains ip addresses corporation , want obscure out every ip address within it. 1 idea had add 1 every digit in file , mod resulting number 256, still remains valid ip.

for e.g 129 become 2310 % 256 = 6

is there quick way apply such change using vim? sounds ambitious, thought i'd still ask. here example of 1 block file.

if (      isinnet(ip, "111.222.123.234", "255.255.255.224")  ||      isinnet(ip, "166.19.10.14", "255.255.255.192") ||   )  {return "direct";} 

here's single search/replace command all:

:s/\d\+/\=substitute(tr(submatch(0), '0123456789', '1234567890'), '0', '10', 'g') % 256/g 

(add own range, e.g. selecting block in visual mode , doing :'<,'>s (or :%s whole file)).

  • we start matching numbers (i.e. sequences of digits: \d\+).
  • for each of rotate digits: 0 becomes 1, 1 becomes 2, ..., 9 becomes 0 (done using tr()).
  • but 9 supposed become 10, not 0, apply substitution turns 0 10 (done using substitute()).
  • the final result taken modulo 256 (% 256).

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -