Oops, hadn't finished.
's/(^\s+test\s+)\d+/ $1 . ++$count /e'
Breaking this down,
s/foo/bar/
means, search $_ ($_ is the current line in many
scripts) for something, and then replace what is
matched with something else.
s/foo(bar)baz/$1/
replaces foobarbaz with bar. Parens "capture"
part of a match. $1 replaces with the captured
bit.
(If you use two parens in the search part, then $2
contains whatever is captured by the second
paren pair, and so on. (Paren pairs can overlap;
the Nth opening parens starts the capture for the
$N variable.) There's lots more subtleties to let
you express what you need, but that can wait. ;>)
s/foo/bar/e
means execute the replacement as if it were perl
expression yielding a result, then use the result of
that as the replacement. (This would be an error
for the example above; bar isn't a perl command.)
s/^foo/bar/
means only match foo at the start of what's in $_.
(Unless you tell perl to be more clever.)
s/\s\d/bar/
means match a white space character, then a
digit.
++$foo
means add one to foo, then use its value.
If $foo is undefined, perl treats it as zero.
So the above comes out as 1 the first time,
2 the second...
$foo . $bar
concatenates $foo and $bar into one string.
So
's/(^\s+test\s+)\d+/ $1 . ++$count /e'
matches any number of white space characters,
the word 'test' then any number of white space
characters, then any number of digits, then
replaces that with everything but the digits,
followed by an incrementing number starting
at 1.
---------
So, one line explained...
;>