博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Vim删除重复行
阅读量:6279 次
发布时间:2019-06-22

本文共 1031 字,大约阅读时间需要 3 分钟。

The following command will sort all lines and remove duplicates (keeping unique lines):

:sort u tips:  here "u" maybe short of the word "unique"  I guess:)

If you need more control, here are some alternatives.

There are two versions, the first leaves only the last line, the second leaves only the first line.

g/^\(.*\)$\n\1$/d g/\%(^\1$\n\)\@<=\(.*\)$/d

Breakdown of the second version:

g//d <-- Delete the lines matching the regexp \@<= <-- If the bit following matches, make sure the bit preceding this symbol directly precedes the match \(.*\)$ <-- Match the line into subst register 1 \%( ) <--- Group without placing in a subst register. ^\1$\n <--- Match subst register 1 followed by end of line and the new line between the 2 lines In this simple format (matching the whole line), it's not going to make much difference, but it will start to matter if you want to do stuff like match the first word only.

This does a uniq on the first word in the line, and deletes all but the first line:

g/\%(^\1\>.*$\n\)\@<=\(\k\+\).*$/d

转载地址:http://zdyva.baihongyu.com/

你可能感兴趣的文章
vim使用点滴
查看>>
embedded linux学习中几个需要明确的概念
查看>>
mysql常用语法
查看>>
Morris ajax
查看>>
【Docker学习笔记(四)】通过Nginx镜像快速搭建静态网站
查看>>
ORA-12514: TNS: 监听程序当前无法识别连接描述符中请求的服务
查看>>
<转>云主机配置OpenStack使用spice的方法
查看>>
java jvm GC 各个区内存参数设置
查看>>
[使用帮助] PHPCMS V9内容模块PC标签调用说明
查看>>
关于FreeBSD的CVSROOT的配置
查看>>
基于RBAC权限管理
查看>>
基于Internet的软件工程策略
查看>>
数学公式的英语读法
查看>>
留德十年
查看>>
迷人的卡耐基说话术
查看>>
PHP导出table为xls出现乱码解决方法
查看>>
PHP问题 —— 丢失SESSION
查看>>
Java中Object类的equals()和hashCode()方法深入解析
查看>>
数据库
查看>>
Vue------第二天(计算属性、侦听器、绑定Class、绑定Style)
查看>>