This is the bash command:
sort -k2 input | uniq -s4
sort -k2 skip the first field when sortinguniq -s4 skip the next 4 characters
In vim, you can invoke the external command above:
:%!sort -k2 % | uniq -s4
- the second
% will expand to the current file name.
Actually, you can sort in vim with this command:
:sort /^\d*\s/
- vim will skip matching numbers when sorting
After sorting, use this command to remove duplicate rows:
:%s/\v(^\d*\s(.*)$\n)(^\d*\s\2$\n)+/\1/
- To avoid too much backslash, I use
\v in the pattern to enable VERY MAGIC . - In a multi-line pattern,
$ will match the position before the newline character ( \n ). I do not think this is necessary here. - You can create your own regular expression.
source share