$ 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 $
In reply to Re^2: Numbering instances of a String in a file
by toolic
in thread Numbering instances of a String in a file
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |