我有一個特殊格式的字符串的巨大的文本文件。我怎樣才能快速創建另一個文件,只有對應我的條件的字符串?如何從文件中只獲取特殊字符串(通過條件)?
例如,文件內容:
[2/Nov/2015][rule="myRule"]"GET
http://uselesssotialnetwork.com/picturewithcat.jpg"
[2/Nov/2015][rule="mySecondRule"]"GET
http://anotheruselesssotialnetwork.com/picturewithdog.jpg"
[2/Nov/2015][rule="myRule"]"GET
http://uselesssotialnetwork.com/picturewithzombie.jpg"
,我只需要字符串 「MyRule的」 和 「貓」? 我認爲它應該是perl或bash,但沒關係。 非常感謝,對於noob問題抱歉。
'grep「myRule。* cat」' - [man grep](http://linux.die.net/man/1/grep) - 一旦您對正則表達式的結果感到滿意,就可以在Perl中使用它(例如使用'=〜'運算符或其他Perl函數)。 –
DevSolar