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

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

Re: function to increase numbers in a buffer


From: Harry Putnam
Subject: Re: function to increase numbers in a buffer
Date: Wed, 23 Apr 2003 06:04:01 GMT
User-agent: Gnus/5.090008 (Oort Gnus v0.08) Emacs/21.3.50 (i686-pc-linux-gnu)

Jordi Burguet Castell <jordi.burguet-castell@cern.ch> writes:

> Or, easier, I have a file that looks like this:
>
> 20      1       23523
> 20      2       23874
> 20      3       23898
> ...
>
> and I want to increase all the numbers in the third column by a certain 
> amount, say 3, from (point) to (point-max). A Perl script would not help, 
> because I need to do it several times and from different points.

Not a very satisfying answer I'm afraid but shell tools or perl can
handle this thru an emacs command `shell-command-on-region' (`M-S-|'),
by selecting the region needed and then use the `C-u' preface to make
the action change the current buffer.

For example, taking this buffer

  22   1  2233
  22   2  2244
  22   3  3355
  22   4  4455

Select a region of lines 2 thru 3 in the usual way by pressing C-spc
at the beginning of line 2 then moving cursor just below line 3.


Then C-u M-S-| awk '{printf "%-4d %-2d %d\n",  $1, $2, ($3 + 3)}' <RET>

Will give you 

  22   1  2233
  22   2  2247
  22   3  3358
  22   4  4455

Emacs allows one to work on a region employing shell or other tools to do
the work.

There are probably better ways, but this one is fairly quick if you
know basic shell/awk/perl stuff and are on a platform where those
tools can be found.


reply via email to

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