regex - 查找带有未终止双引号的行

标签 regex bash sed

对于给定的文件-

测试文件

----------
<At_First_Sight> <isCalled> "A.
<The_Godfather> <isCalled> "A.
<The_Godfather> <isCalled> "Mrr.
<Night_of_the_Comet> <type> "wikicategory_Comedy_science_fiction_films".


Required output should be - 
<Night_of_the_Comet> <type> "wikicategory_Comedy_science_fiction_films".

因为这已经终止了双引号。您也可以假设在 s 行中不会有超过 2 个双引号

Command - ^(.+?\"[^\"]+\.)

似乎可以在基于网络的正则表达式检查器上工作,但不能在 bash 上工作。

最佳答案

使用 egrep 更简单:

egrep '^[^"]*"[^"]*$' file
<At_First_Sight> <isCalled> "A.
<The_Godfather> <isCalled> "A.
<The_Godfather> <isCalled> "Mrr.

如果你想要 sed 然后使用:

sed -n '/^[^"]*"[^"]*$/p' file

关于regex - 查找带有未终止双引号的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23090093/

相关文章:

c++ - VS2010 的 std::regex_match 问题

bash - 检查每行的特定分隔符 - bash

linux - Sed 不能正常工作

regex - 在 Golang 中从 HTML 中提取文本内容

javascript - 正则表达式 - 匹配从特定字符到任何非数字的所有数字

c# - 在 ASP.NET RegularExpressionValidator 中忽略区分大小写

macos - OS X - 返回 "Nothing to be done for <filename>"

linux - 删除行的第一部分,直到找到字符@

ubuntu - SED - 变量上的 "Filename too long"

regex - 在匹配后向字符串添加大括号 (sed)