How to use: g command in order to requirements?

Viewed 124

There is a log file like this:

adsflljl    abc
hgfahld abc
ash;al  abc
a;jfda  cd
asldfj  cd
;aljdf  de
a;dlfj  dh
adads   ae
adfasf  ae
aaaads  hi

I would like to "group" them like this:

adsflljl,hgfahld,ash;al abc
a;jfda,asldfj   cd
;aljdf  de
a;dlfj  dh
adads,adfasf    ae
aaaads  hi

My way is use %s/^\v(.*)\t(.*)\n(.*)\t\2/\1,\3\t\2

I know that the use of replacement several times, i can achieve the above requirements.

But in Vim Regex Duplicate Lines Grouping

the way of user ib is

:g/^\S\+/y|if matchstr(@",@/)==matchstr(getline(line('.')-1),@/)|s//,/|-j!

I changed it to

:g/\t\S\+$/y|if matchstr(@",@/)==matchstr(getline(line('.')+1),@/)|s//,/|j!

But it doesn't work.Why ?How to use: g command in order to achieve the above requirements?

3 Answers
Related