The text I want to process is like (after sorting regardless of the first column:
236|c this is character ace|end but not the same i24|f string f is different|this is the end 235|this is character c|end 235|this is character c|end but 235|this is character c|end but not the same 235|this is character c|end but not the same 422|this is string aa|end of the line 312|this is string af|end but maybe not the same 423|this is string af|end but not the same 123|this is string af|end of line one 422|this is string af|end of the line 422|this is string a|end of the line 51k|this is string e|end but not the same 13d|this is string e|end of the line 341|z string b is different|end of the line but not the same
I want to move all lines duplicated in the middle column to the end of the file. That's, all unique lines appear in the beginning of the file, followed by the duplicated(only duplicated in the middle column) lines.
I have tried
This will end with the first occurrence of the duplicated lines not moved, which works as expected considering I learn this from the method to delete the duplicated lines and leave only the first one.
This time I can get only the unique lines but I lose what I want.
I thought both two approaches can lead to the result, but the questions left respectively are:
- How to move the matched lines in one go, or move the first one after this step; and
- How to delete all lines in file2 which are also in file2(file1 is the original text and file2 contains only unique lines).
Or moving only the unique lines can also reach the goal.
Am I in the right direction? Or any vim-ish/straightforward methods? Thanks.