在shell脚本中提取特定的String

时间:2014-02-20 09:36:52

标签: shell

我有一个文件maned fil1.txt,文件的内容是: -

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

1 个答案:

答案 0 :(得分: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)。