Question: I need to increment named serial and I want to do it with sed. I've done it like this:

```
echo 2015092315 | gsed s/20[0-9][0-9][0-9][0-9]*/`date +%Y%m%d%H`/g

```

But then I realized that updates to zone file might happen more than once an hour and this above will not be enough.

Now I want to increment the serial by 1. How to do that? I came up with a:

```
gsed 's/20[0-9][0-9][0-9][0-9]*/expr & + 1/e'

```

which does work but it deletes the beginning of line (spaces) and the end of the line (comment), and gives error about a comment (sh: serial: not found) which I do not want.

Answer: 
Perl to the rescue:

```
perl -pe 's/(20[0-9]{3,})/$1+1/e' file

```
Combining the original question and choroba's answer you get following one-liner using GNU `sed`:

```
sed -r 's/(20[0-9]{3,8})(.*$)/echo `expr \1 + 1` "\2"/e'

```

Which can be used like this:

```
[admin@localhost ~]$ echo '2015092315 ; serial' | sed -r 's/(20[0-9]{3,8})(.*$)/echo `expr \1 + 1` "\2"/e'
2015092316  ; serial

```

or on a file:

```
[admin@localhost ~]$ sed -i -r 's/(20[0-9]{3,8})(.*$)/echo `expr \1 + 1` "\2"/e' /path/to/zone_file

```