您的位置:首页 > 其它

vim 字符串出现次数统计(词频)

2015-01-16 16:47 1966 查看

命令

:%s/pattern//gn

参数说明

% - 操作区间,全文本;可以使用1, $或行区间替代

s - substitute

pattern - 查询字符串

// - 无替代文本。如果偏好,中间可以加任意字符!建议添加‘~’,重复上次查询

g - Replace all occurrences in the line.  Without this argument,  replacement occurs only for the first occurrence in each line.因此,如果不用此标志,就变成统计出现pattern的行数。

n - Report the number of matches, do not actually substitute.这是核心标志,也是达到目的的标志。同时也说明了为什么'//'之间可以添加任意字符!

用途

单个pattern词频统计

替代方案

脚本或高级语言解析文件
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  vim 词频 统计