Path: utzoo!attcan!lsuc!eci386!jmm From: jmm@eci386.uucp (John Macdonald) Newsgroups: comp.unix.questions Subject: Re: regexp..prepending a line globally (Vi) Message-ID: <1990Jul3.153405.15882@eci386.uucp> Date: 3 Jul 90 15:34:05 GMT References: <1772@island.uu.net> Reply-To: jmm@eci386.UUCP (John Macdonald) Organization: Elegant Communications Inc. Lines: 45 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 |part04.Z |. |. |. etc... | | So far so good. Now what I wanted to do is take the first |line (with the path) and prepend it to every line with a regexp. Assuming that your implication that there is only one of these series present (i.e. only line 1 has a path), an answer is to use the ex side of vi (use Q if you are in vi mode to get to ex mode, or else precede each line with a colon): 3,$g/^/1co.-1 (duplicate the path line in front of all files) g/:$/join (join each pair) %s;: ;/; (change the : to a slash) However, if you have more than one of the path lines mixed in, then this requires much more contorted effort to do - it is easier to use recursive invokations of this technique than to try to get it to work all at once... (again from ex - assuming that the above script is in file "joinup"): $a (ensure that there is always one more colon) : . g/:/.,/:/-1! ex