Vic*_*Lam 16 regex textmate oniguruma
我正在使用textmate来编辑文件.我想删除所有不包含单词的行.这是一个例子.
apple ipad
hp touch pad
samsung galaxy tab
motorola xoom
Run Code Online (Sandbox Code Playgroud)
如何使用单词pad删除所有行,并使用正则表达式获得此结果?
apple ipad
hp touch pad
Run Code Online (Sandbox Code Playgroud)
谢谢大家.
kiz*_*izu 36
替换^(?!.*pad.*).+$为空字符串
我不确定使用正则表达式做这种事情,但你可以很容易地使用grep来做到这一点.
例如,如果文件文件包含以下内容:
apple ipad
hp touch pad
samsung galaxy tab
motorola xoom
Run Code Online (Sandbox Code Playgroud)
打开终端,然后运行以下命令:
grep pad textfile
Run Code Online (Sandbox Code Playgroud)
它输出这个:
apple ipad
hp touch pad
Run Code Online (Sandbox Code Playgroud)
如果要将输出保存到文件,可以执行以下操作:
grep pad textfile > filteredfile
Run Code Online (Sandbox Code Playgroud)