Reputation: 678
I have a file in the following format
1 2472
1 664
2 2600
10 4135
10 5606
...
and I want to convert it to
1 2472 664
2 2600
10 4135 5606
...
Upvotes: 0
Views: 112
Reputation: 378
A reliable complete regex-based solution is also possible.
First, you must highlight non-repeated indices as follow:
:%s/\(^\(\d\).\)\(\(.\|\(\n\)\1\)\+$\)/*\1\3/
Next, must do the collapse of lines with:
:%s/\n\(*.*$\)\@!\d\+ / /
And lastly, remove *
exceed character
:%s/^*//g
Best regards!
Upvotes: 0
Reputation: 6421
You can combine items by executing this command:
:%s/\v(\d+\s)(.*\n\1.*)+/\=substitute(submatch(0),'\n'.submatch(1),' ','g')/
Upvotes: 6