Page 1 of 1

Find/Replace + multiplication?

Posted: Tue Mar 03, 2009 10:32 pm
by cwigley
I received a request to try and research the ability to do a Find/Replace, but apply some basic math on the replace. Basically, locate "X", multiply "X" by 1.2 to get "Y", replace "X" with "Y". Nothing extremely complicated, I just need to figure out the right tool for the job.

We've attempted to accomplish this in VB, but aren't getting the speed we need. I am looking into the JAVA SDK... but i don't really have any Java guys over here.

I'm just looking for a point in the most optimal direction.

Thank you for your help!

Collin

Posted: Tue Mar 03, 2009 11:06 pm
by ben_josephs
With a suitable scripting language you can do this on the command line with a single command. For example, if your X can be any sequence of digits, possibly containing a decimal point (regex: ([0-9]*\.)?[0-9]+ ), you can do it with perl like this:

perl -pe "s/(([0-9]*\.)?[0-9]+)/$1 * 1.2/eg" -i.bak input_file

You can do it in an editor with a scripting facility, but TextPad has no scripting facility.