public inbox for blinux-list@redhat.com
 help / color / mirror / Atom feed
From: Linux for blind general discussion <blinux-list@redhat.com>
To: Linux for blind general discussion <blinux-list@redhat.com>
Subject: Re: ex syntax?
Date: Sat, 21 Dec 2019 19:25:34 -0600	[thread overview]
Message-ID: <20191221192534.55df0f8d@bigbox.attlocal.net> (raw)
In-Reply-To: <alpine.NEB.2.21.1912211945530.16319@panix1.panix.com>

Tim here.

If you're using ed or sed rather than ex/vi/vim, it's pretty easy
depending on what constitutes a "word" (do you include punctuation
as word-separation, or just white-space? What about contractions
like "can't" or abbreviations like "Dr."?).  You can use

6s/[^[:space:]]\{1,\}/replacement/6
6s/[[:alpha:]]\{1,\}/replacement/6

in both cases.  The first 6 is the line-number, the 2nd 6 is the 6th
word in the line.

In ex/vi, it's a bit more complex because they don't support the
numeric flag at the end to indicate the 6th one, so you'd have to do
something atrocious like

6s/\(\([^[:space:]]\{1,\}[[:space:]]\{1,\}\)\{5\}\)[^[:space:]]*/\1replacement/p

(that "5" is the 5 words before the one you want to replace).  It
would generally be easier to just retype the line.

It might be easier to prompt for a replacement:

6s/[^[:space:]]\{1,\}/xxx/gc

and then answer "no" 5 times, then answer "yes" for the 6th one.

If you're running the ex-mode of vim instead of vi, vim provides more
powerful regular expressions so you can do

6s/\(\W*\zs\w\+\)\{6}/replacement

Vim's regex also makes it easy to define what constitutes a
word-vs-not-a-word (using "\w" and "\W") or
whitespace-vs-non-whitespace (using "\s" and "\S").  Depending on how
you define a "word" the ed/sed/ex/vi versions get a lot messier.

Hope this helps,

-Tim (the vi/vim/ed/ex geek behind the @ed1conf account on Twitter)


On December 21, 2019, Linux for blind general discussion wrote:
> On line 6 of a file what is the command to delete word 6 on that
> line? A long time ago when the bsd learn utility was working on a
> system I studied the advanced ex lessons and unfortunately forgot
> that syntax.


  reply	other threads:[~ UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
 Linux for blind general discussion
 ` Linux for blind general discussion [this message]
   ` Linux for blind general discussion

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

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

  git send-email \
    --in-reply-to=20191221192534.55df0f8d@bigbox.attlocal.net \
    --to=blinux-list@redhat.com \
    /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).