Path: utzoo!attcan!uunet!cs.utexas.edu!romp!auschs!d75!panda!eli From: eli@panda.uucp (Eli Taub/100000) Newsgroups: comp.unix.questions Subject: Re: regexp..prepending a line globally (Vi) Keywords: vi, ex, ed Message-ID: <3237@d75.UUCP> Date: 6 Jul 90 16:58:00 GMT References: <1772@island.uu.net> <3235@d75.UUCP> <1990Jul3.155941.6037@chinet.chi.il.us> Sender: news@d75.UUCP Reply-To: eli@reed.UUCP (Eli Taub/100000) Organization: IBM AWD, Austin, TX Lines: 70 In article <1990Jul3.155941.6037@chinet.chi.il.us> les@chinet.chi.il.us (Leslie Mikesell) writes: >In article <3235@d75.UUCP> eli@reed.UUCP (Eli Taub/100000) writes: > >[how to do this in vi]: >>>/usr/spool/ftp/comp.sources.unix/volume22/nn6.4: >>>part01.Z >>>part02.Z >>Comments 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 > >.... > >But since you asked for it ...: > >$s/$/^M:/ > >g/^.*:$/s @^\(.*\):$@.,/:/-1 s!^!\1/!@ \ > >d a \ > >*a > >Good grief! >Just edit the first line into the command for the transformation, delete >it into a register, and execute the register. This gives you a series >of steps you can undo if you mis-type something. > >edit to: >:%s,^,/usr/spool/ftp/comp.sources.unix/volume22/nn6.4/, >with the cursor on that line, type "add (delete to register a) >then @a (execute register a) >if it doesn't look right, just u (undo) "aP (put back from register a) >and try again. The only problem to watch for with this approach is >that you need an extra level of ^V quoting for any special characters >(one to get them into the edit buffer, one to get them into the command). > >Les Mikesell > les@chinet.chi.il.us 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 automaticaly find the correct directory to prepend to each line. For example on the file: /usr: bin etc lib /usr/etc: rup spray /usr/include: core.h curses.h errno.h If you source the code above you'll get: /usr/bin /usr/etc /usr/lib /usr/etc/rup /usr/etc/spray /usr/include/core.h /usr/include/curses.h /usr/include/errno.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. / | \