Path: utzoo!attcan!uunet!ncrlnk!ncrstp!npdiss1!mercer From: mercer@npdiss1.StPaul.NCR.COMDan Mercer) Newsgroups: comp.editors Subject: Re: regexp..prepending a line globally (Vi) Keywords: ed, ex, vi Message-ID: <130@npdiss1.StPaul.NCR.COM> Date: 4 Jul 90 04:39:40 GMT References: <1772@island.uu.net> <3236@d75.UUCP> Reply-To: mercer@npdiss1.StPaul.NCR.COM (Dan Mercer) Organization: StPaul Lines: 57 In article <3236@d75.UUCP> eli@panda.uucp (Eli Taub/100000) writes: :Cross posting from comp.unix.questions: :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 :>part03.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 :>ph: (415) 332 3278 (h), 491 1000 (w) disclaimer: Island's coffee was laced :-) : :The real answer should be - use sed, awk and friends, :or use `find -print' when possible. :But since you asked for it ...: : :$s/$/^M:/ :g/:/s@\(.*\):@,//- s!^!\1/!@\ :d a\ :*a : :[ ^M stands for: V ] : :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 (512) 838-4810 | Who needs emacs when you have vi | | | \ | : | | | /\/ :Contractor at (AWD) IBM | I express my opinions not IBM's. | / | \ The real question was how to prepend lines. You have to remember the two 'anchors': '^' and '$'. T prepend, replace the inital anchor with your text: 1,$s/^/\/usr\/acct\/xxxx.../ Be sure to escape the slashes. -- Dan Mercer Reply-To: mercer@npdiss1.StPaul.NCR.COM (Dan Mercer) "MAN - the only one word oxymoron in the English Language"