2014-02-20 69 views
-1

我有一個文件鬃fil1.txt,以及文件的內容是: -提取shell腳本一個特定的字符串

./pub/index.html                   ./manifest.bak 
./manifest.rel                    ./ns/GSCT_ASNShipmentInfo_E1/node.idf 
./ns/GSCT_ASNShipmentInfo_E1/E1/svcReprocessASNManifest/flow.xml.bak 
./ns/GSCT_ASNShipmentInfo_E1/E1/svcReprocessASNManifest/node.ndf 
./ns/GSCT_ASNShipmentInfo_E1/E1/svcReprocessASNManifest/flow.xml 
./ns/GSCT_ASNShipmentInfo_E1/E1/svcUpdateVR01ForOP/flow.xml.bak 
./ns/GSCT_ASNShipmentInfo_E1/E1/svcUpdateVR01ForOP/node.ndf 
./ns/GSCT_ASNShipmentInfo_E1/E1/svcUpdateVR01ForOP/flow.xml 

我想提取所有我在有flow.xml線結束並將其保存到不同的文件。 輸出文件應該是: -

./ns/GSCT_ASNShipmentInfo_E1/E1/svcReprocessASNManifest/flow.xml 
    ./ns/GSCT_ASNShipmentInfo_E1/E1/svcUpdateVR01ForOP/flow.xml 

回答

3

只需使用grep

$ grep 'flow\.xml$' file > output 
$ cat output 
./ns/GSCT_ASNShipmentInfo_E1/E1/svcReprocessASNManifest/flow.xml 
./ns/GSCT_ASNShipmentInfo_E1/E1/svcUpdateVR01ForOP/flow.xml 

$指示行的結束,所以這是檢查與flow.xml結尾的所有行。另外,.被轉義爲表示文字點,而不是表示「任何字符」的正則表達式(thanks Jojo)。

+0

我認爲你應該逃避你模式中的'.'字符。現在它將匹配以'flowaxml','flowbxml'等結尾的字符串。 – Jojo

+0

不夠公平,只是更新。謝謝!! – fedorqui