public inbox for blinux-list@redhat.com
 help / color / mirror / Atom feed
* ex syntax?
@  Linux for blind general discussion
   ` Linux for blind general discussion
  0 siblings, 1 reply; 3+ messages in thread
From: Linux for blind general discussion @  UTC (permalink / raw)
  To: blinux-list

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.



--


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: ex syntax?
   ex syntax? Linux for blind general discussion
@  ` Linux for blind general discussion
     ` Linux for blind general discussion
  0 siblings, 1 reply; 3+ messages in thread
From: Linux for blind general discussion @  UTC (permalink / raw)
  To: Linux for blind general discussion

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.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: ex syntax?
   ` Linux for blind general discussion
@    ` Linux for blind general discussion
  0 siblings, 0 replies; 3+ messages in thread
From: Linux for blind general discussion @  UTC (permalink / raw)
  To: Linux for blind general discussion

Just white space, I'm doing things with bash scripts.
On Sat, 21 Dec 2019,
Linux for blind general discussion wrote:

> Date: Sat, 21 Dec 2019 20:25:34
> From: Linux for blind general discussion <blinux-list@redhat.com>
> To: Linux for blind general discussion <blinux-list@redhat.com>
> Subject: Re: ex syntax?
>
> 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.
>
>
> _______________________________________________
> Blinux-list mailing list
> Blinux-list@redhat.com
> https://www.redhat.com/mailman/listinfo/blinux-list
>
>

-- 


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~ UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
 ex syntax? Linux for blind general discussion
 ` Linux for blind general discussion
   ` Linux for blind general discussion

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).