zi0h@quads.uchicago.edu (W. Ishii) (01/24/91)
Hello there! As a vi novice (maybe a stronger term is called for--vi idiot, probably), I've been stuck for about a week now trying to figure out how to globally remove multiple blank lines from text. Like those, above this line, in order to neaten up the body of the text while still retaining paragraph integrity. As far as I can tell, I can't just substitute for something like '\12\12\12' with '\12\12' (multiple new-line characters with double new-lines). I think I've tried most every version of that, including literal returns, but nothing seems to work. Crossing lines seems to be tough, and some have suggested sed or tr in lieu of vi, but so far no go. Would anyone out there be able to help me? Please forgive me if this is too rudimentary/frequently-asked, but any info you have would be tremendously useful. Thanks! -- W. Ishii zi0h@midway.uchicago.edu
chris@bilby.cs.uwa.oz.au (chris mcdonald) (01/24/91)
In <1991Jan24.064310.8077@midway.uchicago.edu> zi0h@quads.uchicago.edu (W. Ishii) writes: >Hello there! As a vi novice (maybe a stronger term is called for--vi idiot, >probably), I've been stuck for about a week now trying to figure out how to >globally remove multiple blank lines from text. Filter the whole file (with !<line count>! ) through cat -s -------------------------------------------------------------------------------- Chris McDonald. _--_|\ / \ X_.--._/ v Department of Computer Science, ACSnet: chris@budgie.cs.uwa.oz.au University of Western Australia, ARPA: chris%budgie.cs.uwa.oz.au@uunet.uu.net Mounts Bay Road, FTP: bison.cs.uwa.oz.au, 130.95.1.23 Crawley, Western Australia, 6009. SCUD: (31.97 +/-10% S, 115.81 +/-10% E) PHONE: ((+61) 09) 380 2533 FAX: ((+61) 09) 382 1688
hansm@cs.kun.nl (Hans Mulder) (01/24/91)
In article <chris.664709285@budgie> chris@bilby.cs.uwa.oz.au (chris mcdonald) writes: >In <1991Jan24.064310.8077@midway.uchicago.edu> zi0h@quads.uchicago.edu (W. Ishii) writes: > >>Hello there! As a vi novice (maybe a stronger term is called for--vi idiot, >>probably), I've been stuck for about a week now trying to figure out how to >>globally remove multiple blank lines from text. > >Filter the whole file (with !<line count>! ) through cat -s Close, but no cigar: it's easier to filter the whole file using 1G!Gcat -s^M That way, you don't have to count lines. And when you must use a line count, it's easier to type <line count>!!filter^M Have a nice day, Hans Mulder hansm@cs.kun.nl
weimer@garden.kodak.COM (Gary Weimer (588-0953)) (01/24/91)
In article <chris.664709285@budgie>, chris@bilby.cs.uwa.oz.au (chris mcdonald) writes: |> In <1991Jan24.064310.8077@midway.uchicago.edu> zi0h@quads.uchicago.edu (W. Ishii) writes: |> |> >Hello there! As a vi novice (maybe a stronger term is called for--vi idiot, |> >probably), I've been stuck for about a week now trying to figure out how to |> >globally remove multiple blank lines from text. |> |> Filter the whole file (with !<line count>! ) through cat -s Since he declared himself a "vi idiot," perhaps we should be a little more explicit: 1G!Gcat -s 1G goes to the beginning of the file, !G pipes from current line (the first one in this case) to end of file cat -s removes extra blank lines Gary Weimer
crowley@unmvax.cs.unm.edu (Charlie Crowley) (01/25/91)
In <1991Jan24.064310.8077@midway.uchicago.edu> zi0h@quads.uchicago.edu (W. Ishii) writes: > >Hello there! As a vi novice (maybe a stronger term is called for--vi idiot, >probably), I've been stuck for about a week now trying to figure out how to >globally remove multiple blank lines from text. Another solution is to use the regular expression capabilities of the ex/ed editor underlying vi. To wit: :g/^$/d That is, ':' to signal an ex command, 'g' do this globally, '/^$/ for all blank lines (that is, lines whose beginning (^) and end ($) are right together), 'd' deleted the line Charlie Crowley University of New Mexico
geoff@Veritas.COM (Geoffrey Leach) (01/25/91)
From article <chris.664709285@budgie>, by chris@bilby.cs.uwa.oz.au (chris mcdonald): > In <1991Jan24.064310.8077@midway.uchicago.edu> zi0h@quads.uchicago.edu (W. Ishii) writes: > >>Hello there! As a vi novice (maybe a stronger term is called for--vi idiot, >>probably), I've been stuck for about a week now trying to figure out how to >>globally remove multiple blank lines from text. > > Filter the whole file (with !<line count>! ) through cat -s Try ":g/^$/d"
mcohen@amsaa-cleo.brl.mil (Marty Cohen) (01/25/91)
To: zi0h@midway.uchicago.edu resulted in unknown user zi0h. :g/^ *$/d will delete all lines that consist of nothing but blanks. ^ means beginning of line, $ means end of line in regular expressions. -- Marty Cohen mcohen@brl.mil {uunet|rutgers}!brl!mcohen Custom House Rm 800, Phila. PA 19106 (215)597-8377 -- -- Marty Cohen mcohen@brl.mil {uunet|rutgers}!brl!mcohen Custom House Rm 800, Phila. PA 19106 (215)597-8377
hansm@cs.kun.nl (Hans Mulder) (01/25/91)
In article <1991Jan24.172344.28877@Veritas.COM> geoff@Veritas.COM (Geoffrey Leach) writes: >From article <chris.664709285@budgie>, by chris@bilby.cs.uwa.oz.au (chris mcdonald): >> In <1991Jan24.064310.8077@midway.uchicago.edu> zi0h@quads.uchicago.edu (W. Ishii) writes: >> >>>Hello there! As a vi novice (maybe a stronger term is called for--vi idiot, >>>probably), I've been stuck for about a week now trying to figure out how to >>>globally remove multiple blank lines from text. >> >> Filter the whole file (with !<line count>! ) through cat -s > >Try ":g/^$/d" Try _reading_ the question before you answer. Chris said _multiple_ blank lines. The best you can do using the :g command would be :g/^$/+s//This_line_must_be_deleted :g/This_line_must_be_deleted/d But using 1G!Gcat -s is easier. Have a nice day, Hans Mulder hansm@cs.kun.nl
joshi@cs.uiuc.edu (Anil Joshi) (01/26/91)
hansm@cs.kun.nl (Hans Mulder) writes: >In article <1991Jan24.172344.28877@Veritas.COM> geoff@Veritas.COM (Geoffrey Leach) writes: >>From article <chris.664709285@budgie>, by chris@bilby.cs.uwa.oz.au (chris mcdonald): >>> In <1991Jan24.064310.8077@midway.uchicago.edu> zi0h@quads.uchicago.edu (W. Ishii) writes: >>> >>>>Hello there! As a vi novice (maybe a stronger term is called for--vi idiot, >>>>probably), I've been stuck for about a week now trying to figure out how to >>>>globally remove multiple blank lines from text. >>> >>> Filter the whole file (with !<line count>! ) through cat -s >> >>Try ":g/^$/d" >Try _reading_ the question before you answer. Chris said _multiple_ blank lines. >The best you can do using the :g command would be >:g/^$/+s//This_line_must_be_deleted >:g/This_line_must_be_deleted/d >But using 1G!Gcat -s is easier. What a pain to do such a simple thing in vi. ISPF solution is exclude blank lines delete all exculded lines Anil ISPFBigot -- "Whatever we wish ourselves to be, we have the power to make ourselves. If what we are now has been the result of our own past actions,then it certainly follows that whatever we wish to be in the future, can be produced by our own present actions. how to act." - Vivekananda, Late Nineteenth Century Indian Philosopher
dattier@ddsw1.MCS.COM (David W. Tamkin) (01/27/91)
crowley@unmvax.cs.unm.edu (Charlie Crowley) wrote in <1991Jan24.163844.7521@unmvax.cs.unm.edu>: | In <1991Jan24.064310.8077@midway.uchicago.edu> | zi0h@quads.uchicago.edu (W. Ishii) writes: | > | >Hello there! As a vi novice (maybe a stronger term is called for--vi idiot, | >probably), I've been stuck for about a week now trying to figure out how to | >globally remove multiple blank lines from text. | | Another solution is to use the regular expression capabilities of the ex/ed | editor underlying vi. To wit: | | :g/^$/d Er, uh, not quite. :g/^$/d (or more simply, :v/./d, delete all lines on which a search for . [wildcard for any character except newline] fails) will remove ALL blank lines. The original question was to reduce every series of consecutive blank lines to one blank line. Now, several people have posted that cat -s will do that. *That works only on Berkeley UNIX systems.* The version of cat in System V-land doesn't support that option: it uses -s for "silent" [i.e., don't say anything if a requested input file doesn't exist]. Running something with multiple blank lines through System V's cat -s doesn't strip the extra blank lines. One can always toss together a sed script. If I can get one to work (I've been trying, but hey, I'm an amateur and a novice at this), I'll post it. David Tamkin Box 7002 Des Plaines IL 60018-7002 708 518 6769 312 693 0591 MCI Mail: 426-1818 GEnie: D.W.TAMKIN CIS: 73720,1570 dattier@ddsw1.mcs.com
gast@maui.cs.ucla.edu (David Gast) (01/28/91)
In article <1991Jan25.182043.10324@cs.uiuc.edu> joshi@cs.uiuc.edu (Anil Joshi) writes: >>But using 1G!Gcat -s is easier. >What a pain to do such a simple thing in vi. >ISPF solution is >exclude blank lines >delete all exculded lines ^^^^^^^^ Why do you say that? 1G!Gcat -s is 11 characters including the return. Your solution (if I counted correctly) is 46 characters including the returns. That means that your solution is almost 4 times as long. Further, your solution is not correct. You typed ``exculded'' instead of ``excluded.'' While anyone can make a mistake, the more typing necessary, the more likely it is that there will be a mistake. This newsgroup is primarily devoted to Unix editors. If you think that many people want to discuss ISPF, why not start alt.editors.ispf? Even when I have to use a PC clone, I use vi. David Gast gast@cs.ucla.edu {uunet,ucbvax,rutgers}!{ucla-cs,cs.ucla.edu}!gast
mic@hpfcso.HP.COM (Marc Clarke) (01/29/91)
Under Unix, I simply use: rmnl < file_with_blank_lines > file_without_blank_lines and skip the fun with "vi" and "awk" altogether.
joshi@cs.uiuc.edu (Anil Joshi) (01/29/91)
gast@maui.cs.ucla.edu (David Gast) writes: >In article <1991Jan25.182043.10324@cs.uiuc.edu> joshi@cs.uiuc.edu (Anil Joshi) writes: >>>But using 1G!Gcat -s is easier. >>What a pain to do such a simple thing in vi. >>ISPF solution is >>exclude blank lines >>delete all exculded lines > ^^^^^^^^ >Why do you say that? 1G!Gcat -s is 11 characters including the return. >Your solution (if I counted correctly) is 46 characters including the >returns. That means that your solution is almost 4 times as long. The solution is far shorter if you use only the short forms for exculde etc. i.e. x and d for delete. >Further, your solution is not correct. You typed ``exculded'' instead >of ``excluded.'' While anyone can make a mistake, the more typing necessary, >the more likely it is that there will be a mistake. I have not given the exact syntax. It is the pseudo code but it is close enough. I agree with your point about mistakes. What about debugging, understandability and ease of enhancing? How would one eliminate lines made up of not blanks but say stars (or hyphens or underscores or ...). In vi one ends up writing one macro for each. In ISPF, one would parameterize. So less chance of making mistakes, changes made to this one macro will work in all situations, but in vi one has to keep track of all the macros which have the same form. >This newsgroup is primarily devoted to Unix editors. If you think that >many people want to discuss ISPF, why not start alt.editors.ispf? Even >when I have to use a PC clone, I use vi. From the name I got the impression that this group is for comp.editors. Discussing ISPF will be only academic because it is not available on unix. I see this to be a real disadvantage of unix. >David Gast >gast@cs.ucla.edu >{uunet,ucbvax,rutgers}!{ucla-cs,cs.ucla.edu}!gast Anil Joshi joshi@cs.uiuc.edu -- "Whatever we wish ourselves to be, we have the power to make ourselves. If what we are now has been the result of our own past actions,then it certainly follows that whatever we wish to be in the future, can be produced by our own present actions. how to act." - Vivekananda, Late Nineteenth Century Indian Philosopher
leech@homer.cs.unc.edu (Jonathan Leech) (01/29/91)
In article <1991Jan28.014157.5388@cs.ucla.edu> you write: |> This newsgroup is primarily devoted to Unix editors. If you think that |> many people want to discuss ISPF, why not start alt.editors.ispf? Even |> when I have to use a PC clone, I use vi. Heaven forbid we Unix weenies learn anything about non-Unix editors. Considering the amount of vi traffic in this group, it would make more sense to create comp.editors.vi. Jon Leech (leech@cs.unc.edu) __@/
ndh@stl.stc.co.uk (Neale D Hind ) (01/29/91)
My contribution to the great global line removal debate: From within vi use - :g/^[spacetabformfeed]*$/d ---------------- This deletes any line that contains any combination of any number of only linefeeds, tabs, spaces and formfeed characters. For spacetabformfeed use the spacebar, tab key or Ctrl+I, Ctrl+V Ctrl+L ---------------- ---- Neale D. Hind - (N.D.Hind@stl.stc.co.uk)
dylan@ibmpcug.co.uk (Matthew Farwell) (01/30/91)
In article <973@borg.cs.unc.edu> leech@homer.cs.unc.edu (Jonathan Leech) writes: > Considering the amount of vi traffic in this group, it would make >more sense to create comp.editors.vi. That may not be a bad idea actually. I think the traffic would justify the split. I personally read comp.editors only for the vi stuff, and I really don't want to know about any other editor.... Dylan. -- Matthew J Farwell | Email: dylan@ibmpcug.co.uk The IBM PC User Group, PO Box 360,| ...!uunet!ukc!ibmpcug!dylan Harrow HA1 4LQ England | CONNECT - Usenet Access in the UK!! Phone: +44 81-863-1191 | Sun? Don't they make coffee machines?
crowley@unmvax.cs.unm.edu (Charlie Crowley) (01/30/91)
Well, the first time I read this I misunderstood and thought he wanted to get rid of all blank lines. I looked at the title and not closely enough at the text. Getting rid of all but one is harder. Solutions so far: (1) filtering through cat -s (on bsd systems) (2) using awk -- pretty easy if you know awk (3) using sed -- somewhat complex I found a way (albeit complex) to do it from within vi. (1) find a string that does not occur anywhere in the text. I will use 'qqq' below. It is easy to check by searching for it and getting a failure. /qqq (2) replace all blank lines withi this string :g/^$/s/^/qqq/ (3) Join all such lines. This must be done one step at a time where each step joins half of the remaining lines. :g/qqq$/j :g/qqq$/j :g/qqq$/j :g/qqq$/j You have to do it until it does not affect any lines. The four above will work if no run of blank lines is more than 32 blank lines. If you :set report=1 you will find out whether it affected any lines. At this point all the 'qqq 's for each run of blank lines are all on the same line. The ' ' is a side effect of the join (j). (4) Replace the first one of these with a newline. :%s/qqq /^M/ where the '^M' was produced by ^V then ^M. There are no control characters in the above two lines for this presentation but they are needed when you type the command into vi. (5) Remove all the extra 'qqq 's. :%s/qqq //g Okay, it is complex. It did it in X by having the command lines in a file and copying them into vu using the X selection. I tried combining them into a macro but I got confused in a morass of ^Vs. Maybe someone more expert in vi :map's can tell me how to do it. The two flaws are the need to find a unique string (minor) and the need to iterate the step (3) command. Charlie Crowley Univ. of New Mexico Computer Science Department
les@chinet.chi.il.us (Leslie Mikesell) (01/30/91)
In article <1991Jan28.214646.10668@cs.uiuc.edu> joshi@cs.uiuc.edu (Anil Joshi) writes: >>>ISPF solution is >>>exclude blank lines >>>delete all exculded lines > >>Why do you say that? 1G!Gcat -s is 11 characters including the return. >>Your solution (if I counted correctly) is 46 characters including the >>returns. That means that your solution is almost 4 times as long. Does the ISPF solution actually solve the original problem, which was to translate multiple blank lines into a single blank line? Cat -s does that, but only if your unix is BSD-ish. >I agree with your point about mistakes. What about debugging, understandability >and ease of enhancing? How would one eliminate lines made up of not blanks but >say stars (or hyphens or underscores or ...). In vi one ends up writing one >macro for each. In ISPF, one would parameterize. So less chance of making >mistakes, changes made to this one macro will work in all situations, but in vi >one has to keep track of all the macros which have the same form. Vi has no problem with most line oriented operations - you can do deletions with :g/pattern/d - hardly worth writing a macro for. However, arbitrarily unusual transformations can be done by piping through external tools and under unix they are perhaps best done that way. It's the cases that are just slightly unusual that make vi seem a bit weak, like multi-line patterns and paragraph reformatting. Les Mikesell les@chinet.chi.il.us
hansm@cs.kun.nl (Hans Mulder) (01/30/91)
In article <1991Jan30.001551.7538@unmvax.cs.unm.edu> crowley@unmvax.cs.unm.edu (Charlie Crowley) writes: >Well, the first time I read this I misunderstood and thought he wanted to >get rid of all blank lines. I looked at the title and not closely enough >at the text. Getting rid of all but one is harder. Solutions so far: You are not the only one to make that mistake. >(1) filtering through cat -s (on bsd systems) >(2) using awk -- pretty easy if you know awk >(3) using sed -- somewhat complex (4) using perl -- pretty easy if you know perl >I found a way (albeit complex) to do it from within vi. Far too complex, I might add. >(1) find a string that does not occur anywhere in the text. I will use >'qqq' below. It is easy to check by searching for it and getting a failure. > /qqq > >(2) replace all blank lines with this string > :g/^$/s/^/qqq/ Much better idea: (2') replace all but the first blank line with this string: :g/^$/+s//qqq/ This changes the next line, but only if ^^^^ it, too, matches the pattern. (3') Delete all lines containing the string: :g/qqq/d Enjoy, Hans Mulder hansm@cs.kun.nl
cadman@cbnewsm.att.com (jerome.schwartz) (01/31/91)
In article <1991Jan30.000549.11742@ibmpcug.co.uk>, dylan@ibmpcug.co.uk (Matthew Farwell) writes: > > Considering the amount of vi traffic in this group, it would make > >more sense to create comp.editors.vi. > > That may not be a bad idea actually. I think the traffic would justify > the split. > > I personally read comp.editors only for the vi stuff, and I really don't > want to know about any other editor.... > > Dylan. Yes, let's do it. Jerry ********************************************************************** Jerome Schwartz | Standard Disclaimer: AT&T Bell Laboratories | 600 Mountain Ave. | Views expressed are my own and Murray Hill, N.J. 07974-2070 | do not necessarily reflect those Phone : (201)-582-3070 | of my employer. **********************************************************************
ttobler@unislc.uucp (Trent Tobler) (01/31/91)
From article <1991Jan24.172344.28877@Veritas.COM>, by geoff@Veritas.COM (Geoffrey Leach): > From article <chris.664709285@budgie>, by chris@bilby.cs.uwa.oz.au (chris mcdonald): >> In <1991Jan24.064310.8077@midway.uchicago.edu> zi0h@quads.uchicago.edu (W. Ishii) writes: >> >>>Hello there! As a vi novice (maybe a stronger term is called for--vi idiot, >>>probably), I've been stuck for about a week now trying to figure out how to >>>globally remove multiple blank lines from text. >> >> Filter the whole file (with !<line count>! ) through cat -s > > Try ":g/^$/d" Or if you want all lines deleted that are empty, or contain entirely tabs or spaces... :g/^[ \t]*$/d --- Trent Tobler ttobler@csulx.weber.edu
abed@venus.wustl.edu (Abed M. Hammoud) (01/31/91)
In article <1991Jan30.000549.11742@ibmpcug.co.uk> dylan@ibmpcug.CO.UK (Matthew Farwell) writes: >In article <973@borg.cs.unc.edu> leech@homer.cs.unc.edu (Jonathan Leech) writes: >> Considering the amount of vi traffic in this group, it would make >>more sense to create comp.editors.vi. > >That may not be a bad idea actually. I think the traffic would justify >the split. > >I personally read comp.editors only for the vi stuff, and I really don't >want to know about any other editor.... > >Dylan. >-- I Also like to see a separate newsgroup for VI. -------------------------------------------------------------- | Abed M. Hammoud abed@saturn.wustl.edu| | Washington University. office:(314)726-7547 | | Electronic Systems & Signals Research Laboratory. | | Dept. of Electrical/Biomedical Engineering. | | St.Louis Mo U.S.A | --------------------------------------------------------------
ndh@stl.stc.co.uk (Neale D Hind ) (01/31/91)
In the referenced article crowley@unmvax.cs.unm.edu (Charlie Crowley) writes: >I found a way (albeit complex) to do it from within vi. >(1) find a string that does not occur anywhere in the text. I will use >(2) replace all blank lines withi this string >(3) Join all such lines. This must be done one step at a time where >(4) Replace the first one of these with a newline. >(5) Remove all the extra 'qqq 's. >Okay, it is complex. It did it in X by having the command lines in a file Surely if you know which blank line you want to keep, it would be simpler to use one of the other methods to remove all blank lines and then manually insert the one you wanted to keep. My contribution was :g/^[spacetabformfeed]*$/d from witihn vi. ---- Neale D. Hind - (N.D.Hind@stl.stc.co.uk)
prs@tcsc3b2.tcsc.com (Paul Stath) (02/01/91)
If the user is writing text, as indicated by the paragraphs comment, why not just run the text through `uniq(1)`? This of course assumes that there are no consecutive duplicated lines other than empty ones. '1G!Guniq Seems simpler than 'cat -s' and works the same in all flavors of Unix. (If you know a flavor that uniq doesn't work like this, please tell me about it. I wouldn't want to use such a system, and I'll know which ones to avoid. :-)
gardner@shl.com (Gardner Buchanan) (02/01/91)
>> > Considering the amount of vi traffic in this group, it would make >> >more sense to create comp.editors.vi. >Yes, let's do it. Count me in too. I'm just not interested in weirdo DOS/VSE, NOSS VM/CMS, EDT, Norton-Commando stuff. Just give me vi (on Unix) and I'll be happy. -- Gardner Buchanan gardner@shl.com Systemhouse, Ottawa (613) 236-6604 x375
asylvain@felix.UUCP (Alvin "the Chipmunk" Sylvain) (02/02/91)
In article <1991Jan24.064310.8077@midway.uchicago.edu> zi0h@quads.uchicago.edu (W. Ishii) writes: > > Hello there! As a vi novice (maybe a stronger term is called for--vi idiot, > probably), I've been stuck for about a week now trying to figure out how to > globally remove multiple blank lines from text. Thot I'd go ahead and add one more way to do this. This uses the `lex' tool available on most UNIX systems and look-alikes. Write a `lex' input script as follows: (call the file `nuke_mt_line.lex') %% ^[ \t]*\n[ \t\n]* printf ("\n"); . ECHO; The %% separates the empty defintions from the rules. The rules follow fairly typical UNIX regular expressions. The first rule says: ^ (beginning of line) [ \t]* (0 or more spaces or tabs [that *is* a space there before the \t]) \n (newline) [ \t\n]* (0 or more spaces, tabs or newline) <is replaced by> printf ("\n"); (output a single newline) The second rule says: . (anything on the line, ended by newline) <is replaced by> ECHO; (output unaltered) To generate working code from this, you perform the following steps: lex -t nuke_mt_line.lex > nuke_mt_line.c cc -o nuke_mt_line nuke_mt_line.c -ll You can test this easily by creating an input file with multiple empty lines. Include spaces and tabs on the empty lines. Execute as follows: nuke_mt_line < nuke_test_in > nuke_test_out Then you can try it from a `vi' filter, much the same way as many of the other suggestions posted using `cat -s'. (inside `vi') 1G!Gnuke_mt_line^M (which translates to) 1G (go to beginning of file) ! (filter using an external shell program) G (using all text from here to end of file as input to that program) nuke_mt_line (this is the external program you just made) ^M (natch, you gotta terminate with a carriage return!) This has the advantage of working even on systems where there is no BSD version of `cat -s' available, and it's a hell of a lot simpler than using `awk' or `sed'. Furthermore, the program generated will be rela- tively small, so it should load into memory faster than `awk' or `sed'. The only real disadvantage to using `lex' in general is that it's just as convoluted to figure out how to use as both `awk' and `sed'. -- asylvain@felix.UUCP (Alvin "the Chipmunk" Sylvain) =========== Opinions are Mine, Typos belong to /usr/ucb/vi =========== "We're sorry, but the reality you have dialed is no longer in service. Please check the value of pi, or see your SysOp for assistance." =============== Factual Errors belong to /usr/local/rn =============== UUCP: uunet!{hplabs,fiuggi,dhw68k,pyramid}!felix!asylvain ARPA: {same choices}!felix!asylvain@uunet.uu.net
asylvain@felix.UUCP (Alvin "the Chipmunk" Sylvain) (02/06/91)
In article <30211@megaron.cs.arizona.edu> rupley@cs.arizona.edu (John Rupley) writes: > > In article <156430@felix.UUCP>, asylvain@felix.UUCP (Alvin "the Chipmunk" > Sylvain) writes: > :In article <1991Jan24.064310.8077@midway.uchicago.edu> zi0h@quads.uchicago.edu > :(W. Ishii) writes: > :> I've been stuck for about a week now trying to figure out how to > :> globally remove multiple blank lines from text. > : > :Thot I'd go ahead and add one more way to do this. This uses the `lex' > :tool available on most UNIX systems and look-alikes. > : [......] > : %% > : ^[ \t]*\n[ \t\n]* printf ("\n"); > : . ECHO; > > This fails for two reasons: > > 1. It deletes leading whitespace after a blank line. > > 2. A sufficiently large number of blank lines blow the > lex buffer. > > The following works, I believe: > > %% > ^[ \t]*\n/[ \t]*\n ; > .|\n ECHO; John, you're right, mine does fail for reason 1. (I'm not that con- cerned over reason 2. Any tool has it's limitations. I'm assuming the poster didn't want to write specialized code, which could have very easily handled the problem, just throwing away unwanted newlines. Out- side of that, you use the tool and accept the limits.) Yours does overcome reason 1. Obviously, I didn't test for 2. That's why I don't much like lex. The level of unpredictability rises very quickly with a slow increase of complexity. Sometimes, it seems quicker to write specialized code. Nevertheless, once you work the bugs out, it's a very useful tool. And, once you've figured out lex's quirks, it should be quicker than cutting code for the applications it's designed for. It almost certainly will be faster than any sed or awk program written for this particular job. -- asylvain@felix.UUCP (Alvin "the Chipmunk" Sylvain) =========== Opinions are Mine, Typos belong to /usr/ucb/vi =========== "We're sorry, but the reality you have dialed is no longer in service. Please check the value of pi, or see your SysOp for assistance." =============== Factual Errors belong to /usr/local/rn =============== UUCP: uunet!{hplabs,fiuggi,dhw68k,pyramid}!felix!asylvain ARPA: {same choices}!felix!asylvain@uunet.uu.net
steveha@microsoft.UUCP (Steve HASTINGS) (02/07/91)
In article <2704@wn1.sci.kun.nl> hansm@cs.kun.nl (Hans Mulder) writes: > :g/^$/+s//qqq/ This changes the next line, but only if > ^^^^ it, too, matches the pattern. This inspired me to come up with the following. Note that it is only possible to use this in ex mode; you have to use Q to exit vi to ex mode, and you can use the ex "vi" command to switch back. -- cut here -- cut here -- cut here -- cut here -- cut here -- cut here -- g/^[ <tab>]*$/.,/[^ <tab>]/-1c\ \ . -- cut here -- cut here -- cut here -- cut here -- cut here -- cut here -- This finds all runs of lines containing only whitespace, and changes them to a single line with no characters on it. I was trying to put this in a file and execute it from vi with a :source command, but I couldn't make it work. Can anyone tell me why it shouldn't work that way? -- Steve "I don't speak for Microsoft" Hastings ===^=== ::::: uunet!microsoft!steveha steveha@microsoft.uucp ` \\==|