On Wed, Jan 11, 2012 at 12:40:53PM -0600, John Johnson wrote:

> I basically have a template website designed and have standard strings
> for images (IMG001, IMG002…)
> 
> The photographer, however, provides me with a bunch of photos that are
> non-sequential and named differently (DSC_0022, DSC_0033, DSC_101,
> NNMT_23…)
> 
> I am thinking that I could have one or two files that would let me use
> BBEdit to map from one string to the new string, with a global multi-file
> search and replace (I could always put the files in the same place, to
> make this easier, with standard names.) It sounds easy, but I'm not sure
> the best way to go about it in BBEdit. Something like,
> 
> Read Line 1 (oldstring, newstring)
> Replace all instances of oldstring with newstring
> Loop until EOF

It sounds like you want to do the same thing that was discussed in this
thread from October:

<http://groups.google.com/group/bbedit/browse_thread/thread/6e782e4bea6a0e66>

This was my solution:

#!perl 

use strict; 

my %dict; 

while (<DATA>) { 
  chomp; 
  /\t/ or next; 
  my ($old, $new) = split /\t/, $_; 
  $dict{$old} = $new; 
} 

my $re = 
  '\b(' . 
    join('|', map "\Q$_\E", sort { length $b <=> length $a } keys %dict) . 
  ')\b';

while (<>) { 
  s/$re/$dict{$1}/g; 
  print; 
}

__END__
old-term        new-term
another-old-term        another-new-term

This script is set up to be used as a filter on selected text in the front
window, and reads the list of substitutions from the end of its own file.
It could be modified to modify multiple files in-place, and/or to read the
list of substitutions from an external file.


I do wonder, though, if this is the best approach to solving your problem.
I would also consider renaming the files or using a pre-packaged templating
system.


Ronald

-- 
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