wmartin@brl-smoke.ARPA (Will Martin ) (06/11/86)
Hi! I hope this group (net.text) is the right one for these questions; I'm afraid they are rather simplistic compared to the more advanced topics this group seems to concentrate upon (based on a review of recent subject lines) but I don't know where else to ask. They could not be answered by our most experienced local users of "vi", and I guess I am the next-most-experienced vi user here, so I must turn to the net for aid. ("Here" is an Army activity in St. Louis called "ALMSA".) In the version of "vi" that comes with 4.2 BSD, what commands do I use to search for the following text? 1) Two (or more) blank lines, one after the other. 2) A line longer than "n" characters. (For the former, I've tried various combinations of ^$ and Ctrl-V-Return, but none have worked. For the latter, I would suppose that "/^(81 dots)$" would find lines over 80 characters long, but that is hardly practical. I would expect there to be a more elegant solution... :-) Advice & help appreciated! Regards, Will Martin UUCP/USENET: seismo!brl-smoke!wmartin or ARPA/MILNET: wmartin@almsa-1.ARPA
ken@rochester.ARPA (Comfy chair) (06/20/86)
|1) Two (or more) blank lines, one after the other. | |2) A line longer than "n" characters. | |(For the former, I've tried various combinations of ^$ and |Ctrl-V-Return, but none have worked. For the latter, I would suppose |that "/^(81 dots)$" would find lines over 80 characters long, but |that is hardly practical. I would expect there to be a more elegant |solution... :-) This looks like a job for... Superchicken, er, awk. vi: (1) vi can't match across lines, so no joy. (2) There is no counted form of the * operator. awk: (1) Have a variable remember previous line was blank. (2) See builtin 'length'. You may also want to print out the line number for use later. Ken -- UUCP: ..!{allegra,decvax,seismo}!rochester!ken ARPA: ken@rochester.arpa Snail: CS Dept., U. of Roch., NY 14627. Voice: Ken!
john@cecil.UUCP (john knight) (06/20/86)
> ~ How to select lines of length 40 while in vi?
Use vi to filter your file thru awk. You can write an
awk script which marks the lines you want to treat.
Here is an example:
1G #start at line 1
!Gawk ' {if (length > 40) {print "mark"$0} else print}' #filter file thru awk
g/mark/cmds #do your thing
The unique power of UNIX (UPOU) is that vi includes awk. All tools are
designed to be included in all other tools.
john
"What a difference a [Gg] makes!"
aglew@ccvaxa.UUCP (06/24/86)
>In the version of "vi" that comes with 4.2 BSD, what commands do I >use to search for the following text? > >1) Two (or more) blank lines, one after the other. > >2) A line longer than "n" characters. I'm afraid that you can't do this directly in vi, without going into a shell. I'm sure that I will be flamed if I'm wrong. But - you can do it in GNU EMACS by quoting the newline. Just one among the many reasons to use EMACS. Andy "Krazy" Glew. Gould CSD-Urbana. USEnet: ihnp4!uiucdcs!ccvaxa!aglew 1101 E. University, Urbana, IL 61801 ARPAnet: aglew@gswd-vms