07-08-2011, 05:26 AM | #1 |
Enthusiast
Posts: 29
Karma: 10
Join Date: Apr 2009
Device: none
|
search and replace with incremental number
Hi,
I'm looking for a software (a free one if possible) that can search through a html file and replace the replacement string with an incremental number. I've looked around a bit but can't find it. Anyone has any ideas? Thanks a lot |
07-08-2011, 06:14 AM | #2 |
frumious Bandersnatch
Posts: 7,514
Karma: 18512745
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
|
vim can: http://imhotep.koalabs.org/?p=121
|
Advert | |
|
07-08-2011, 06:45 AM | #3 |
Enthusiast
Posts: 29
Karma: 10
Join Date: Apr 2009
Device: none
|
Hey, thanks for replying,
I had already found the webpage you're talking about but I don't have a clue as to how to use this with vim. I downloaded vim (for windows), got a GUI to open but that's it. Where should i put this? thanks |
07-08-2011, 08:49 AM | #4 |
frumious Bandersnatch
Posts: 7,514
Karma: 18512745
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
|
I don't know, I've never used it with a GUI, always in a text console. You better get a tutorial on vim, because it's not like notepad... While in command (not edit) mode, you write ":let i=1|etc.", without the quotes (note the colon).
|
07-08-2011, 02:41 PM | #5 |
Witless protection Agent
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"; } |
Advert | |
|
Thread Tools | Search this Thread |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
search and replace - drops blanks in replace ? | cybmole | Conversion | 10 | 03-13-2011 03:07 AM |
macro - Search and Replace | oldbwl | Workshop | 17 | 03-05-2011 01:39 PM |
Search and replace not working | helmerer | Conversion | 4 | 02-25-2011 03:48 AM |
Search and replace in 0.2.0 | paulpeer | Sigil | 7 | 03-13-2010 11:59 AM |
Why no search and replace? | charleski | Sigil | 10 | 11-24-2009 04:13 PM |