perl - compute difference of number in file using perldo -
i have file 2 numbers
4 4 4 4 9 8 7 7 each line may have different number of spaces. use perldo compute difference of 2 numbers:
i trying right now
:perldo @a=split(/ +/, $_); $_ = $a[0] - $a[1] i think should work file not changed @ all.
how can using perldo?
i don't know perl, works here:
:perldo @a=split(/ +/, $_); $_ = $a[0] - $a[1]; print $_ since editing file in vim, consider in vim way:
:%s/\v(\d+)\s*(\d+)/\=submatch(2)-submatch(1)
Comments
Post a Comment