help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Add +2 to all numbers in file


From: Katsumi Yamaoka
Subject: Re: Add +2 to all numbers in file
Date: Fri, 27 Feb 2009 17:32:22 +0900
User-agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.0.91 (gnu/linux)

>>>>> sharky wrote:
> I have a file with a lot of numbers. It looks like this:

> xx, xx, xx--xx, xx, xx, x
> xx, x, xx--xx, xx--xx, x
> xx, xx
> xx, xx, xx--xx, xx--xx, xx--xx

> You get the picture. Can I make emacs add 2 to each and everyone of
> these numbers?

> Please help!

Try `M-x all+2 RET':

(defun all+2 ()
  (interactive "*")
  (save-excursion
    (goto-char (point-min))
    (while (re-search-forward "[0-9]+" nil t)
      (replace-match (number-to-string
                      (+ 2 (string-to-number (match-string 0))))))))


reply via email to

[Prev in Thread] Current Thread [Next in Thread]