Replace 如何删除文本文件每行上一个单词后的所有内容?
我有一个文本文件,看起来有点像这样Replace 如何删除文本文件每行上一个单词后的所有内容?,replace,editor,Replace,Editor,我有一个文本文件,看起来有点像这样 356, http://linkgoeshere.com/4445555 title="The Chariot"> <br /> 356, http://linkgoeshere.com/4445555 title="fddsfssfd"> <br /> 356, http://linkgoeshere.com/4445555 title="T3434534535"> <br /> 356,http://
356, http://linkgoeshere.com/4445555 title="The Chariot"> <br />
356, http://linkgoeshere.com/4445555 title="fddsfssfd"> <br />
356, http://linkgoeshere.com/4445555 title="T3434534535"> <br />
356,http://linkgoeshere.com/4445555 title=“战车”>
356, http://linkgoeshere.com/4445555 title=“fddsfssfd”>
356, http://linkgoeshere.com/4445555 title=“T3434534535”>
我想把所有的东西都留给链接,然后删除后面的所有东西,但是后面的每个部分都是唯一的,除了标题=之外,所以我无法查找和替换
(本btw约800条线路)
有没有什么方法可以通过编程来实现这一点
谢谢。在
Notepad++
中,您可以使用正则表达式查找和替换
- 单击菜单
搜索-->替换…
- 在
选择搜索模式下
正则表达式
- 在
查找内容中输入正则表达式
”\stitle=“.$
- 将
替换为
框为空
- 单击“全部替换”
6.2.2中测试
这也适用于支持使用正则表达式查找和替换的其他编辑器。
- 编辑器方式(vim):
用vim打开文件,键入:%s/title=。$//g
,您将看到结果
事实上,任何支持regex-replace的编辑器都可以工作
- 脚本编程:
sed
(注意:下面的命令将进行适当的更改。)
awk:
不带正则表达式的复杂方法:
awk '{print $1,$2}' file
您可以在stdout上看到输出。您可以通过awk…>newFile将其重定向到文件
如果编辑器不支持正则表达式,请使用Excel将该文件作为csv文件导入(数据->来自文本)并告诉excel使用空格作为字段分隔符。然后将前两列导出为新的csv文件。只是为了澄清说明,这是您想要的输出行吗?356,http://linkgoeshere.com/4445555
awk '{print $1,$2}' file