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: sharky
Subject: Re: Add +2 to all numbers in file
Date: Fri, 27 Feb 2009 01:11:52 -0800 (PST)
User-agent: G2/1.0

On Feb 27, 9:32 am, Katsumi Yamaoka <yama...@jpl.org> wrote:
> >>>>> 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))))))))


I love you. It works perfectly.

Thanks for saving me from several hours of work!

/Sharky


reply via email to

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