in reply to Numbering instances of a String in a file

Oh great Perl Monks, I have tried a few of your solutions and they all do a very fine job of replicating the file, but they do not concatenate the numbers at all :-/ What could I be missing?
  • Comment on Re: Numbering instances of a String in a file

Replies are listed 'Best First'.
Re^2: Numbering instances of a String in a file
by toolic (Bishop) on Jun 07, 2010 at 19:28 UTC
    This works for me in my linux shell:
    $ cat prog.pl use strict; use warnings; my $cnt = 1; while (<>) { s/$/sprintf '%04d', $cnt++/e if /^\*+$/; print; } $ $ $ cat file.txt foo boo *** goo hoo *********************************** bloo $ $ $ perl prog.pl file.txt foo boo ***0001 goo hoo ***********************************0002 bloo $