Joining two lines of text based on pattern

From Vim Tips Wiki

Jump to: navigation, search
Tip 1043 Printable Monobook Previous Next

created 2005 · complexity basic · author mej · version 5.7

Let's say you copy and pasted a bunch of output from CVS like this:

/opt/data/cvs/ofc/ofc/R1/wlthmgmt/common/feeds/state/logship.state.conf,v  <-- logship.state.conf
new revision: 1.4; previous revision: 1.3
Checking in statemch/logship.statemch.conf;
/opt/data/cvs/ofc/ofc/R1/wlthmgmt/common/feeds/statemch/logship.statemch.conf,v  <--  logship.statemch.conf
new revision: 1.4; previous revision: 1.3
Checking in swift/logship.swift.conf;
/opt/data/cvs/ofc/ofc/R1/wlthmgmt/common/feeds/swift/logship.swift.conf,v  <-- logship.swift.conf
new revision: 1.3; previous revision: 1.2
Checking in tmark/logship.tmark.conf;
/opt/data/cvs/ofc/ofc/R1/wlthmgmt/common/feeds/tmark/logship.tmark.conf,v  <-- logship.tmark.conf
new revision: 1.4; previous revision: 1.3

and you want to submit the filename and revision as a promotion request.

You can do a bunch of ":s/foo//" commands to get rid some of the junk there, and a ":g/^Check/d" and ":g/^done" to get rid of the extraneous line and you'd be left with maybe something like this:

-- 1.4 -- install
-- 1.2 -- install
-- 1.4 -- install
-- 1.5 -- install
-- 1.3 -- install

What would you do to "join" the lines with filenames with lines with versions and commands? What *would* you do!?


It could be anything on the line with the filename on it, but you want to say globally search for "whatever" (conf) in this case, and do the ex/ed command "j" on it which joins it with the next line.

[edit] Comments

Transform XML output of cvs2cl ( into the format required for a promotion request. --xml gives you all the data and metadata you need.

Personal tools