(Ted Harding) wrote:
On 12-Nov-09 10:45:02, nev young wrote:
(Ted Harding) wrote:
Interesting thread! Now that it looks as though vim is romping home in its rightful place at the head of the field, let me ask advocates of other editors how they would achieve the following editing task.
You have a long document, in which are lots of occurrences of numbers which have the Contintental separator system ("." to separate thousands, "," for the decimal point). So, for instance, one million Francs and 25 Centimes is 1.000.000,25
Now run a global edit to convert these into the Real Thing, so that the above example becomes 1,000,000.25 for instance.
<untested and from memory> for vi / vim
:1,$s/([0-9]).([0-9])/\1~#~\2/g :1,$s/([0-9]),([0-9])/\1.\2/g :1,$s/~#~/,/g
That's basically exactly it -- except don't use "~#~" for the first replacement (since "~" is special). I assume you wanted to plant a pattern which would very probably be unique to its context (rather than simply "#"), in view of your last line.
Bother. I'd forgotten tilda was special but I CBA to write "some unique string" ;-)
<anecdote> Back in about 1977 when "word processing" was all new and shiny I watched a salesman demonstrate the power of text replacement on the new "word processing machine" by taking a document and replacing every letter "a" with an "e". Then he showed how they could all be changed back, along with every "e" that had been there to start with. Oh how we laughed at him. </anecdote>