On Thu, Oct 26, 2006 at 08:15:31PM +0200, Cindy-Jane Armbruster wrote:
> In one of my projects I have named and numbered "items" (in this case  
> it's definitions, propositions, and remarks on a website on  
> mathematics). The numbering is consecutive, according to a certain  
> system. I have now added an "item" - and need the numbers of the  
> items following the new item increment by one.
> 
> Example of original data:
> definition_b.12
> remark_b.13
> remark_b.14
> proposition_b.15
> 
> Here is as far that I got with my grep find/replace:
> 
> ([ngzk])([_ ])([bB])\.14
> \1\2\3\.15
> 
> The problem is, I currently have 40 "items" - which translates into  
> up to 40 find/replaces - which is a lot of work by hand. I'm sure  
> there must be a smarter way. But I'm new to Grep, and BBedit - so,  
> I'm hoping someone here might be able to help me?

GREP's not well suited for this, because you can't put expressions in the
replacement.  A filter would be easier, such as this one in Perl, which
does allow expressions in the replacement:

#!/usr/local/bin/perl -w

use strict;

while (<>) {
  s/([ngzk][_ ][bB]\.)(\d+)/$1 . ($2 + 1)/e;
  print;
}

__END__


Save that as a filter.  Then, select just the lines you want to update and
run the filter.

You could also write it to filter and renumber the whole document at once:

#!/usr/local/bin/perl -w

use strict;

my $num = 0;

while (<>) {
  s/([ngzk][_ ][bB]\.)\d+/$1 . ++$num/e;
  print;
}

__END__


HTH,
Ronald

-- 
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <[EMAIL PROTECTED]>, not to the list.
List FAQ: <http://www.barebones.com/support/lists/bbedit_talk.shtml>
List archives: <http://www.listsearch.com/BBEditTalk.lasso>
To unsubscribe, send mail to:  <[EMAIL PROTECTED]>

Reply via email to