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
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
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
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
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,
On 03/09/2021, Marc Chantreux wrote:
>> 'abc' in FILE, from within vi.
>
> * % means 'the current file' in vi commands so you can write
That's helpful; thank you!
> * | is the command separator
> * grep has a -c flag to count occurrences
>
> so you can write:
>
> :w|grep -c abc %
That
> 'abc' in FILE, from within vi.
* % means 'the current file' in vi commands so you can write
* | is the command separator
* grep has a -c flag to count occurrences
so you can write:
:w|grep -c abc %
you can also write the content of the buffer to a pipe (my prefered
solution here):
9 matches
Mail list logo