对于给定的文件-
测试文件
----------
<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/