unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Harry Putnam <hgp@sbcglobal.net>
Subject: Re: function to increase numbers in a buffer
Date: Wed, 23 Apr 2003 06:04:01 GMT	[thread overview]
Message-ID: <m2sms9px66.fsf@sbcglobal.net> (raw)
In-Reply-To: b84gt0$ctd$1@news.service.uci.edu

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	other threads:[~2003-04-23  6:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-04-22 13:50 function to increase numbers in a buffer Jordi Burguet Castell
2003-04-23  6:04 ` Harry Putnam [this message]
2003-04-23  6:50 ` Joakim Hove
2003-04-23 12:01 ` Stefan Reichör

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2sms9px66.fsf@sbcglobal.net \
    --to=hgp@sbcglobal.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).