in reply to decrementing numbers
I have tried several variations with 'sed'
use Perl :)
#!/usr/bin/perl -p s/(\d+\.\d+\.\d+\.)(\d+)/$1${\($2-1)}/;
Usage:
$ ./decrement.pl infile >outfile
Update: alternatively, you could use the /e option, which treats the substitution part as Perl code (instead of as a double-quoted string):
s/(\d+\.\d+\.\d+\.)(\d+)/$1.($2-1)/e; # or (just to show another variant) s/(\d+\.\d+\.\d+\.)(\d+)/"$1".($2-1)/e;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: decrementing numbers
by JavaFan (Canon) on Mar 05, 2010 at 17:24 UTC |