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
becomes1
,1
becomes2
, ...,9
becomes0
(done usingtr()
). - but
9
supposed become10
, not0
, apply substitution turns0
10
(done usingsubstitute()
). - the final result taken modulo 256 (
% 256
).
Comments
Post a Comment