[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
How to replace-regexp by the average?
From: |
gnuist006 |
Subject: |
How to replace-regexp by the average? |
Date: |
Fri, 5 Jun 2015 13:30:40 -0700 (PDT) |
User-agent: |
G2/1.0 |
Given strings of this type
TOKEN 123.456 12.3456 1234.56
replace by
TOKEN 67.9008 623.453
where the first number is the average, ie what you get from the evaluation of
(/ (+ 123.456 12.3456) 2.0)
and second is also the average, ditto
(/ (+ 1234.56 12.3456) 2.0)
both upto 6 significant digits.
I tried this but it does not work.
(save-excursion (replace-regexp "TOKEN \\([0-9\\.]+\\) \\([0-9\\.]+\\)
\\([0-9\\.]+\\)" (concat "TOKEN (format "6.6f" (/ (+ \\1 \\2) 2.0)) (format
"6.6f" (/ (+ \\2 \\3) 2.0)) ) ))
Any help in improving while keeping it readable one-liner sexp and maintaining
the use of \\1 \\2 \\3 etc if possible ... ?
Cheers,
Bolega
- How to replace-regexp by the average?,
gnuist006 <=