View Single Post
Old 07-08-2011, 02:41 PM   #5
FatDog
Witless protection Agent
FatDog ought to be getting tired of karma fortunes by now.FatDog ought to be getting tired of karma fortunes by now.FatDog ought to be getting tired of karma fortunes by now.FatDog ought to be getting tired of karma fortunes by now.FatDog ought to be getting tired of karma fortunes by now.FatDog ought to be getting tired of karma fortunes by now.FatDog ought to be getting tired of karma fortunes by now.FatDog ought to be getting tired of karma fortunes by now.FatDog ought to be getting tired of karma fortunes by now.FatDog ought to be getting tired of karma fortunes by now.FatDog ought to be getting tired of karma fortunes by now.
 
Posts: 290
Karma: 1002898
Join Date: Nov 2009
Location: Los Angeles
Device: Kindle
Do you have Perl installed? If not you can install Strawberry perl.

Copy the following code to a file called "bump_number.pl".

Then you can convert the string to a increasing number like this:

Open a Command window (Start->Run->"cmd")

type my_page.html | perl bump_number.pl > my_page_2.html

The new file "my_page_2.html" will have your string replaced with a number that increases from 1.

WARNING: This code assumes your target string only appears 1 time per row. In the example below the word "Buick" appeared twice on the same row and both strings were given the same number.

Code:
#!/usr/bin/perl
# Perl script that will:
# - Read each row from standard input
# - Look for a sub-string and replace it with a number
# - Bump the nunber
# - Write each row out to standard output.
#
# Example:
# If your input file is my_page.html you do this:
#       type my_page.html | perl bump_number.pl > my_page_2.html
#
my $lTargetString = 'Buick';
my $lNumber = 1;
my $lRow;

while ( $lRow = <STDIN> ) {
        chomp ($lRow);
        if ( index ( $lRow, $lTargetString ) > -1 ) {
                $lRow =~ s/$lTargetString/$lNumber/g;
                $lNumber++;
        }
        print "$lRow\n";
}
FatDog is offline   Reply With Quote