I just want it to count!
March 26, 2011 9:37 PM   Subscribe

In Dreamweaver, I am using the find and replace tool. I want to change 1 to n+1, down the list. How?

This question may sound stupid and basic, but I am a n00b.

I have several hundred lines mixed in with other code that say: <value>1</value>

I want to find each line that says
<value>1</value>

and replace each line as a sequence like this
<value>1</value>
<value>2</value>
<value>3</value>
<value>4</value>
...

Similarly, I have another line repeated several hundred times that reads:
<image>Image1.jpg</image>

and I also want those lines to increase incrementally like this:
<image>Image1.jpg</image>
<image>Image2.jpg</image>
<image>Image3.jpg</image>
<image>Image4.jpg</image>
<image>Image5.jpg</image>
...

I have been replacing each number by hand one by one, driving myself nuts. Will someone please teach me how to automate this?! Thank you so much!
posted by at the crossroads to Computers & Internet (3 answers total)
 
I doubt any software's search and replace will do it, unless it lets you do backreferences, variables, and arithmetic.

If Dreamweaver has macros you could write one. Otherwise your best bet is to run the file through an external program.

Here's a quick script I threw together for example:
my $counter;
while (<>) {
  s{<>([^<0>}{"<>$2" . ($counter ? ++$counter : ($counter = $3)) . "$4"}e;
  print;
}
You can save this to a file, download Perl, and run it with "perl script.pl htmlfile.html".

It will look for the first instance of <image> and replace a number it finds inside there. It will start the sequence off with the first number it finds that way. You can have it look for a different number by setting $counter to something, and you can change the image to have it look for a different tag.
posted by vsync at 10:04 PM on March 26, 2011 [1 favorite]


er, have it look forstart with a different number by setting
posted by vsync at 10:04 PM on March 26, 2011


That went horribly; Metafilter ignores CDATA, escapes some pointy brackets, munges others. Here
posted by vsync at 10:07 PM on March 26, 2011 [1 favorite]


« Older I need software to handle my company's job...   |   I need emo music. But I don't have any. Newer »
This thread is closed to new comments.