Path: utzoo!attcan!uunet!cs.utexas.edu!romp!auschs!d75!panda!eli From: eli@panda.uucp (Eli Taub/100000) Newsgroups: comp.editors Subject: Re: regexp..prepending a line globally (Vi) Keywords: ed, ex, vi Message-ID: <3242@d75.UUCP> Date: 6 Jul 90 17:42:01 GMT References: <1772@island.uu.net> <3236@d75.UUCP> <130@npdiss1.StPaul.NCR.COM> Sender: news@d75.UUCP Reply-To: eli@reed.UUCP (Eli Taub/100000) Organization: IBM AWD, Austin, TX Lines: 60 In article <130@npdiss1.StPaul.NCR.COM> mercer@npdiss1.StPaul.NCR.COM (Dan Mercer) writes: #In article <3236@d75.UUCP> eli@panda.uucp (Eli Taub/100000) writes: #:In article <1772@island.uu.net> daniel@island.uu.net (Daniel Smith - OPD Gang) writes: #:> All my years in vi and this one stumps me! I wanted #:>to make a real quick shell script, taken from the output #:>of an ls-lR on uunet. So, I get these lines: #:> #:>/usr/spool/ftp/comp.sources.unix/volume22/nn6.4: #:>part01.Z #:>part02.Z #: ... Stuff deleted ... #:>What I want to end up with is: #:>/usr/spool/ftp/comp.sources.unix/volume22/nn6.4/part01.Z #:>/usr/spool/ftp/comp.sources.unix/volume22/nn6.4/part02.Z #:> Daniel #:> dansmith@well.sf.ca.us daniel@island.uu.net unicom!daniel@pacbell.com #: #:$s/$/^M:/ #:g/:/s@\(.*\):@,//- s!^!\1/!@\ #:d a\ #:*a #: #:To use, simply insert the above lines into a file, say exls, #:and source it like `so' in (ex) command mode: :so exls #: Eli Taub # #The real question was how to prepend lines. ... #1,$s/^/\/usr\/acct\/xxxx.../ # #Be sure to escape the slashes. ^^^^^^^^^^^^^^^^^^---> just use `!': %s!^!/usr/acct/xxxx! #Dan Mercer #Reply-To: mercer@npdiss1.StPaul.NCR.COM (Dan Mercer) You are quite correct if you only had one directory to prepend to ALL the lines, but what do you do with the output of say `ls -R /usr' ? The above code will find the correct directory to prepend to EACH line. For example on the file: /usr: bin etc /usr/etc: rup spray /usr/include: core.h curses.h If you source the code above you'll get: /usr/bin /usr/etc /usr/etc/rup /usr/etc/spray /usr/include/core.h /usr/include/curses.h And you can undo the whole thing with 1 `u'!! _ |___ Eli Taub | | \ | (512) 838-4810 | /\/ Contractor at (AWD) IBM I express my opinions not IBM's. / | \