删除以括号开头的特定字符串[以括号结尾]

时间:2014-12-19 23:25:47

标签: regex awk sed

使用sed

删除包含以括号[并以括号结尾]的特定字符串的行
<p>["1284" align="" width="210" caption="blue sky"]<a href="http://www.domain.com/planes/2014/12/amazing-sky.html"><img class="alignleft size-full wp-image-1084" title="blue sky" src="http://www.domain.com/images/2014/12/amazing-sky.jpg" alt="blue sky" width="210" height="210" /></a></p>
<p>The <em>Blue Sky</em> airplane has the most powerful jet engine, <strong>Carter technicians</strong>, has proposed to expand the plane's wings.</p>

我有大约两万篇需要在目录中清理的文章。我想删除 来自文章的["1084" align="" width="210" caption="blue sky"]。但是,所有这些都略有不同 除了它以括号[并以括号结尾]

开头

2 个答案:

答案 0 :(得分:2)

使用     sed 's/\[[^]]*\]//g'
它将删除[text]

的所有单词

答案 1 :(得分:1)

您可以使用:

sed -i.bak '/\[.*\]/d' file

删除[...]模式的任何行。

-i.bak将使用.bak扩展名保存原始文件。

相关问题