Here's a Perl script that can work as a Unix Filter. It replaces all 
instances of 'the' with 'the#' where # goes from 1 to number of 
occurrences. You just have to replace the $str variable at the top with a 
regex you want to find and alter. Below is sample before and after effect 
of the script.

Sample before:
some text the example for the place.
some text theatre example for th place.
some text the example for the place.

Sample after:
some text the1 example for the2 place.
some text theatre example for th place.
some text the3 example for the4 place.

-------
#!/usr/bin/perl
my $str = '\bthe\b';
my $iter = 0;
while (<>) {
if ($_ =~ m/${str}/){
my $n1 = $_;
while ($n1 =~ m/(${str})/) {
$iter++;
$n1 =~ s/(${str})/$1${iter}/;
}
print $n1;
}
else {
print "$_";
}
}
-------


-Kendall


On Monday, September 3, 2012 2:42:36 AM UTC-4, AB wrote:
>
> Can anyone help with a script or text filter to add a number after a 
> string in a file, starting at 1 at the first occurrence from the top of the 
> file and incrementing by one at each subsequent occurrence ? The string is 
> "<appel>" but could anything.
>
> I have tried to adapt scripts found here, but all I have managed to do so 
> far is to sequentially number every character in a file...
>
> Thanks !
>
> AB
>

-- 
-- 
You received this message because you are subscribed to the 
"BBEdit Talk" discussion group on Google Groups.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
<http://groups.google.com/group/bbedit?hl=en>
If you have a feature request or would like to report a problem, 
please email "[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>



Reply via email to