2014-04-15 37 views
3

對於給定的文件 -查找符合無端接雙引號

test_file裏面

---------- 
<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". 

由於這已經終止doublt quotes.Also you`可以假設,都會有不超過2個引號s的線路

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

似乎對基於Web的regex檢查工作,但沒有工作的bash。

回答

4

更容易egrep的:

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

如果你想那麼如何使用sed:

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