On 04/09/2021, Parodper <parod...@gmail.com> wrote: > O 04/09/21 ás 18:25, ropers escribiu: >> On 04/09/2021, Parodper <parod...@gmail.com> wrote: >>> So I wrote >>> :!sed s/abc/abc\/g % | grep -c abc >>> and then went back and pressed <ENTER> after that backslash, i.e. >>> :!sed s/abc/abc\<ENTER>/g % | grep -c abc >>> And it gave me a correct number of abc's for my test text. >> >> I feel like the dumbest person in the world asking this, but what >> EXACTLY do you mean by "and then went back"? >> Are you using cursor keys? I.e. should I have gotten those to work in >> vi in xterm and console? Because I haven't. The moment I try to >> cursor back, I'm back to vi mode and the ex-style command mode line at >> the bottom is gone. > > Yeah, moving the cursor back and pressing enter. On the vi subject, > since I don't have my OpenBSD machine at hand I was testing this on > Debian GNU/Linux with sed --posix, and it has vim instead of vi.
Ah. That explains it. I believe I mentioned at the start that I had a solution for vim (%s/abc//gn) that I was trying to replicate in OpenBSD's (n)vi. And my sed solution with the \n from a little later also worked on Linux, but not on OpenBSD. Close, but no cigar. >> 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 >> :!grep -c abc % >> on its own -- which won't count multiple same-line occurrences. >> >> A still confused >> Ian >> > > Now it is my turn to feel dumb. I was so focused on the newline-sed > subject that I forgot about that, so I did not put multiple abc's on the > same line :). > > On that subject > :! grep -o abc % | wc -l > seems to work for me. JACKPOT! That does the trick, and it's a perfect solution: short, standard commands, no inscrutable syntax, and no script required. Good man. That's very well spotted. I would not have spotted that on the grep man page, and I didn't. One really has to give what's there an extremely close reading to catch on to the fact that -o won't miss even multiple same-line matches: > Print each match, but only the match, not the entire line. And of course once they're printed, piping them to wc is a proverbial piece of. Is there an argument for adding a note to the man page that multiple same-line matches will each and all be printed? 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, with different quirks than those encountered on the actual ksh prompt. But the primary itch is well and truly scratched. Thank you so much! Ian (Ian Ropers)