faq misc
info misc
intro misc
**
> Date: Sun, 5 Sep 2021 09:11:21 +1000
> From: Reuben ua Bríġ
> easy peasy. to sed all spaces into newlines
you might as well just
sed 'y/ /\n/'
the inverse is almost as easy
sed '1h;1!H;$!d;g;y/\n/ /'
im sure yoar kicking yourself for not seeing such a simple solution.
> Date: Sun, 5 Sep 2021 09:11:21 +1000
> From: Reuben ua Bríġ
> > Date: Sat, 4 Sep 2021 23:22:29 +0100
> > From: ropers
>
> > It's still a little disconcerting to me how getting sed to play nice
> > with \n *from inside vi* still seems like a bridge too far
>
> easy peasy. to sed all spa
> Date: Sat, 4 Sep 2021 23:22:29 +0100
> From: ropers
> It's still a little disconcerting to me how getting sed to play nice
> with \n *from inside vi* still seems like a bridge too far
easy peasy. to sed all spaces into newlines from nvi, enter
:!sed 's/ /&^V^M/g;y/^V^M/\n/'
echoed a
On 04/09/2021, Parodper wrote:
> O 04/09/21 ás 18:25, ropers escribiu:
>> On 04/09/2021, Parodper wrote:
>>> So I wrote
>>> :!sed s/abc/abc\/g % | grep -c abc
>>> and then went back and pressed after that backslash, i.e.
>>> :!sed s/abc/abc\/g % | grep -c abc
>>> And it gave me a correct number
On 04/09/2021, Marc Chantreux wrote:
> hello,
>
>> :!sed s/abc/abc\n/g % | grep -c abc
>
> Note: in sed, "what i just matched" is noted &
Oh, that's good, thank you.
*Shoulda seenit on the man page -- butta dinnt.*
>From sed(1):
> An ampersand (‘&’) appearing in the replacement is replaced
On Sat, Sep 04, 2021 at 05:00:29PM +0100, ropers wrote:
> However, that's as inaccurate as, or potentially even more inaccurate
> than your version, at least as far as vim-ilarity is concerned. My
> awk-ward incantation matches vim's :%s/abc//gn precisely.
Not sure if this is less "awk-ward":
:%
O 04/09/21 ás 18:25, ropers escribiu:
On 04/09/2021, Parodper wrote:
So I wrote
:!sed s/abc/abc\/g % | grep -c abc
and then went back and pressed after that backslash, i.e.
:!sed s/abc/abc\/g % | grep -c abc
And it gave me a correct number of abc's for my test text.
I feel like the dumbest p
> Otherwise, if I try to just type
> :!sed s/abc/abc\/g % | grep -c abc
> and press enter, I only get the same output I also get out of
same here! I so much wish it worked!
regards
marc
hello,
> That's a neat trick -- IFF you can be *sure* that character won't show
> up in the text. I also feel it's a workaround
this is ok as you can easily check if if the caracter won't show. this
is a "good enough" principle: don't try to fix *all* the cases, just fix
yours.
> understand *why
hello,
> :!sed s/abc/abc\n/g % | grep -c abc
Note: in sed, "what i just matched" is noted &
> Googled information suggests that the opposite of what's described in
> the man page may be true: You CAN use a literal newline, but you
> can't use \n.
BSD sed is more litteral AFAIK so you need to
On 04/09/2021, Parodper wrote:
> I think I found something. From POSIX
> (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.html):
> > A line can be split by substituting a into it. The
> > application shall escape the in the replacement by preceding
> > it by a .
Are you or is
On 04/09/2021, Marc Chantreux wrote:
>
> :w !tr -cs '[:alnum:]' '\n'|grep -c abc
>
Is tr's -s option there to eliminate multiple newlines?
If so, is there harm in omitting it, since grep won't count those anyway?
:w !tr -c '[:alnum:]' '\n' | grep -c abc
I think your one-liner is not bad.
O 04/09/21 ás 14:26, ropers escribiu:
On 04/09/2021, Parodper wrote:
To use newlines with sed I use tr and a char I know does not appear
on the text, like '|' or '`'. I just tested :!sed s/abc/abc€/g % |
tr '€' '\n' | grep -c abc and it worked fine.
That's a neat trick -- IFF you can be *sure
On 04/09/2021, Parodper wrote:
> To use newlines with sed I use tr and a char I know does not appear on
> the text, like '|' or '`'. I just tested
> :!sed s/abc/abc€/g % | tr '€' '\n' | grep -c abc
> and it worked fine.
That's a neat trick -- IFF you can be *sure* that character won't show
up in
hello,
> > so you can write:
> >
> > :w|grep -c abc %
> That doesn't really fit the bill:
> 1. This error message is produced: 'The grep command is unknown'
because i wasted it by missing the bang
:w|!grep -c abc %
is a single line way to write
:w
:!grep -c abc %
> 2. grep
O 04/09/21 ás 12:12, ropers escribiu:
However, I can't get the newline to work right in OpenBSD's sed. It
does work in GNU sed.
man sed has this:
The escape sequence \n matches a newline character embedded in the
pattern space. You can't, however, use a literal newline character
in an addres
Self-follow-up:
I.
I've just realised I made a careless error in trying to literally
reproduce your careless mistake, even though it should have been
obvious this was incorrect or at least incomplete. Instead of just
:w !grep -c
clearly you meant:
:w !grep -c abc
Though as noted before,
18 matches
Mail list logo