Forum Moderators: phranque

Message Too Old, No Replies

serialize files?

serialize,replace,instances,number,order,replace

         

happystinky

5:16 pm on Jan 28, 2006 (gmt 0)

10+ Year Member



This is probably much easier than it looks to me. I'm trying to replace all instances of one particular 3-character string with a number that relates to ordering the instances.

For example,

some file = some file
some file #*$! = some file 2
some file xxx xxx = some file 3
some file xxx xxx xxx = some file 4
some file xxx xxx xxx xxx = some file 5
ETC

There should never be more than 15 instances of xxx on a single line in case that matters.

Thanks so much!

happystinky

6:40 pm on Jan 28, 2006 (gmt 0)

10+ Year Member



I think another way to put this is it should replace each encountered series of abc on a line (abc are the actual 3 letters that are needing to be replaced) with the number of times it was found on a single line.

Just want to make sure that isn't too confusing.

If I have:

someword
someword abc
someword abc abc
someword abc abc abc
someword abc abc abc abc
some phrase
some phrase abc
some phrase abc abc

I should end up with:

someword
someword 2
someword 3
someword 4
someword 5
some phrase
some phrase 2
some phrase 3

I hope that makes better sense.

I know I could do multiple search and replace to:

replace
abc abc abc abc
with
5

replace
abc abc abc
with
4

replace
abc abc
with
3

replace
abc
with
2

ETC and end up with

someword
someword 1
someword 2
someword 3
ETC

The problem is, that would end up being about 15 steps to do one thing and I want to do it all w/one single string. I know it can be done, just no idea how.

Thanks in advance!

happystinky

6:43 pm on Jan 28, 2006 (gmt 0)

10+ Year Member



by the way, up above I noticed that if I use the triple x character string that you must have a spam or badwords filter in place that turns it into #*$!

So, anywhere that says #*$! should really be tripple x. Hope that makes sense. For some reason, it only appears to remove the first instance of the string which must be a bug. Anyway, just thought I'd point that out.

jdMorgan

8:36 pm on Jan 28, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you're talking about using mod_rewrite to rewrite URLs of that form, then there's no simple answere, other than the 15 separate rules you mentioned. If you have httpd.conf access, you could use RewriteMap to call a cgi script to compute the number of instances and return the URL form that you want. But mod_rewrite itself is not really usable as a scripting language at that level -- It's meant as a URL substitution 'language' rather than as a 'powerful' scripting language.

Jim

happystinky

8:57 pm on Jan 28, 2006 (gmt 0)

10+ Year Member



Thank you Jim. I see what you're saying.

Actually though, this is more of a question about regular expressions and Search and Replace to replace one series of word combinations within a file with the new combinations. I'm using a search and replace application to do this and the results will then be used on my server so we can build a database that will utilize the results of the S & R.

I'm thinking something along the lines of:

Search for: a

Replace with: b

where

a = regular expression to find and count all instances of abc on a line

b = number of instances abc was found on given line.

Any idea how that might be done?

jdMorgan

9:08 pm on Jan 28, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A PERL script, maybe?

Jim