4
I want to join multiple lines in a file based on a pattern that both lines share.
This is my example:
{101}{}{Apples}
{102}{}{Eggs}
{103}{}{Beans}
{104}...
...
{1101}{}{This is a fruit.}
{1102}{}{These things are oval.}
{1103}{}{You have to roast them.}
{1104}...
...
I want to join the lines {101}{}{Apples}
and {1101}{}{This is a fruit.}
to one line {101}{}{Apples}{1101}{}{This is a fruit.}
for further processing.
Same goes for the other lines.
As you can see, both lines share the number 101, but I have no idea how to pull this off. Any Ideas?
/EDIT:
I found a "workaround":
First, delete all preceding "{1" characters from group two in VISUAL BLOCK mode with C-V
(or similar shortcut), then sort all lines by number with :%sort n
, then join every second line with :let @q = "Jj"
followed by 500@q
.
This works, but leaves me with {101}{}{Apples} 101}{}{This is a fruit.}
. I would then need to add the missing characters "{1" in each line, not quite what I want. Any help appreciated.
What is the maximum number in each group? Are there any lines that would remain unmatched in either group? – Paused until further notice. – 2011-01-30T21:37:42.217
The maximum number in each group is {219} / {1219}. No, all files would match. – ryz – 2011-01-30T21:46:45.743