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 escape a real 0x10 but
both GNU and BSD support escaped newlines:

        sed 's/abc/&\
        /g'

This doesn't help in vi so you can fake it for a moment using tr:

        sed 's/abc/&œ/g' | tr œ '\n'

Another solution is to write commands for this kind of tasks: 

<<\. cat > ~/x
#! /bin/ksh

sed -r 's/a/&\
/g'
.

then from vi, :w !~/x

> literal carriage return, not a literal newline (^J).  That's the case
> on Linux as well, and I don't know why.

neither do i.

> Your new subject line is slightly imprecise, as words are usually
> whitespace-delimited, and I was "looking for a way to count
> occurrences of
> 'abc' in FILE".  Not every substring is a word.

right ... wasn't thinking that much to the name. sorry :)

regards
marc

Reply via email to