2016-12-01 30 views
0

我試圖搜索一行文件名以在一行中包含此信息: <filename>S1A_GRDH。然而,當我使用下面的命令,我得到的是不包括除了線路信息線我想FILEOUT的grep for .txt中指定的單詞返回不需要的行

$ grep "=\"filename"\>" | grep "\S1A_\" | grep "GRDH" fileout >> s1_gg.txt

樣本:

<title>S1B_IW_GRDH_1SDV_20161113T055721_20161113T055746_002936_004FB6_2A93</title> 
    <link href="https://scihub.copernicus.eu/dhus/odata/v1/Products('f97e7088-3d9d-4f88-bc8b-23027dbeb964')/$value"/> 
    <link rel="alternative" href="https://scihub.copernicus.eu/dhus/odata/v1/Products('f97e7088-3d9d-4f88-bc8b-23027dbeb964')/"/> 
    <link rel="icon" href="https://scihub.copernicus.eu/dhus/odata/v1/Products('f97e7088-3d9d-4f88-bc8b-23027dbeb964')/Products('Quicklook')/$value"/> 
    <id>f97e7088-3d9d-4f88-bc8b-23027dbeb964</id> 
    <summary>Date: 2016-11-13T05:57:21.177Z, Instrument: SAR-C SAR, Mode: VV VH, Satellite: Sentinel-1, Size: 1.66 GB</summary> 
    <str name="uuid">f97e7088-3d9d-4f88-bc8b-23027dbeb964</str> 
    <str name="acquisitiontype">NOMINAL</str> 
    <str name="filename">S1B_IW_GRDH_1SDV_20161113T055721_20161113T055746_002936_004FB6_2A93.SAFE</str> 
    <str name="gmlfootprint">&lt;gml:Polygon srsName="http://www.opengis.net/gml/srs/epsg.xml#4326" xmlns:gml="http://www.opengis.net/gml"&gt; 
     &lt;gml:outerBoundaryIs&gt; 
      &lt;gml:LinearRing&gt; 
      &lt;gml:coordinates&gt;51.329529,5.606034 51.745312,1.813976 53.240158,2.187638 52.821747,6.108649 51.329529,5.606034&lt;/gml:coordinates&gt; 
      &lt;/gml:LinearRing&gt; 
     &lt;/gml:outerBoundaryIs&gt; 
    &lt;/gml:Polygon&gt;</str> 
    <str name="format">SAFE</str> 
    <str name="identifier">S1B_IW_GRDH_1SDV_20161113T055721_20161113T055746_002936_004FB6_2A93</str> 
    <date name="ingestiondate">2016-11-13T12:50:19.53Z</date> 
    <str name="instrumentshortname">SAR-C SAR</str> 
    <str name="sensoroperationalmode">IW</str> 
    <str name="instrumentname">Synthetic Aperture Radar (C-band)</str> 
    <str name="swathidentifier">IW</str> 
    <str name="footprint">POLYGON ((5.606034 51.329529,1.813976 51.745312,2.187638 53.240158,6.108649 52.821747,5.606034 51.329529))</str> 
    <int name="missiondatatakeid">20406</int> 
    <str name="platformidentifier">2016-025A</str> 
    <int name="orbitnumber">2936</int> 
    <int name="lastorbitnumber">2936</int> 
    <str name="orbitdirection">DESCENDING</str> 
    <str name="polarisationmode">VV VH</str> 
    <str name="productclass">S</str> 
    <str name="producttype">GRD</str> 
    <int name="relativeorbitnumber">110</int> 
    <int name="lastrelativeorbitnumber">110</int> 
    <str name="platformname">Sentinel-1</str> 
    <date name="beginposition">2016-11-13T05:57:21.177Z</date> 
    <date name="endposition">2016-11-13T05:57:46.175Z</date> 
    <str name="size">1.66 GB</str> 
    <int name="slicenumber">15</int> 
    <str name="status">ARCHIVED</str> 
    <bool name="processed">false</bool> 
    </entry> 
<title>S1A_IW_GRDH_1SDV_20161112T060623_20161112T060648_013905_01661B_ECEF</title> 
<link href="https://scihub.copernicus.eu/dhus/odata/v1/Products('c0b070a1-cf49-4cd8-b72f-47003cf7a048')/$value"/> 
<link rel="alternative" href="https://scihub.copernicus.eu/dhus/odata/v1/Products('c0b070a1-cf49-4cd8-b72f-47003cf7a048')/"/> 
<link rel="icon" href="https://scihub.copernicus.eu/dhus/odata/v1/Products('c0b070a1-cf49-4cd8-b72f-47003cf7a048')/Products('Quicklook')/$value"/> 
<id>c0b070a1-cf49-4cd8-b72f-47003cf7a048</id> 
<summary>Date: 2016-11-12T06:06:23.524Z, Instrument: SAR-C SAR, Mode: VV VH, Satellite: Sentinel-1, Size: 1.64 GB</summary> 
<str name="uuid">c0b070a1-cf49-4cd8-b72f-47003cf7a048</str> 
<str name="acquisitiontype">NOMINAL</str> 
<str name="filename">S1A_IW_GRDH_1SDV_20161112T060623_20161112T060648_013905_01661B_ECEF.SAFE</str> 
<str name="gmlfootprint">&lt;gml:Polygon srsName="http://www.opengis.net/gml/srs/epsg.xml#4326" xmlns:gml="http://www.opengis.net/gml"&gt; 
    &lt;gml:outerBoundaryIs&gt; 
     &lt;gml:LinearRing&gt; 
     &lt;gml:coordinates&gt;50.937958,3.404580 51.348900,-0.315099 52.843983,0.056133 52.430630,3.900550 50.937958,3.404580&lt;/gml:coordinates&gt; 
     &lt;/gml:LinearRing&gt; 
    &lt;/gml:outerBoundaryIs&gt; 
&lt;/gml:Polygon&gt;</str> 
<str name="format">SAFE</str> 
<str name="identifier">S1A_IW_GRDH_1SDV_20161112T060623_20161112T060648_013905_01661B_ECEF</str> 
<date name="ingestiondate">2016-11-12T13:18:49.099Z</date> 
<str name="instrumentshortname">SAR-C SAR</str> 
<str name="sensoroperationalmode">IW</str> 
<str name="instrumentname">Synthetic Aperture Radar (C-band)</str> 
<str name="swathidentifier">IW</str> 
<str name="footprint">POLYGON ((3.404580 50.937958,-0.315099 51.348900,0.056133 52.843983,3.900550 52.430630,3.404580 50.937958))</str> 
<int name="missiondatatakeid">91675</int> 
<str name="platformidentifier">2014-016A</str> 
<int name="orbitnumber">13905</int> 
<int name="lastorbitnumber">13905</int> 
<str name="orbitdirection">DESCENDING</str> 
<str name="polarisationmode">VV VH</str> 
<str name="productclass">S</str> 
<str name="producttype">GRD</str> 
<int name="relativeorbitnumber">8</int> 
<int name="lastrelativeorbitnumber">8</int> 
<str name="platformname">Sentinel-1</str> 
<date name="beginposition">2016-11-12T06:06:23.524Z</date> 
<date name="endposition">2016-11-12T06:06:48.523Z</date> 
<str name="size">1.64 GB</str> 
<int name="slicenumber">11</int> 
<str name="status">ARCHIVED</str> 
<bool name="processed">false</bool> 
</entry> 
<entry> 

輸出的樣本,其中包括了額外的不利線:

<str name="filename">S1B_IW_GRDH_1SDV_20161113T055721_20161113T055746_002936_004FB6_2A93.SAFE</str> 
<str name="identifier">S1B_IW_GRDH_1SDV_20161113T055721_20161113T055746_002936_004FB6_2A93</str> 
<title>S1A_IW_GRDH_1SDV_20161112T060623_20161112T060648_013905_01661B_ECEF</title> 
<str name="filename">S1A_IW_GRDH_1SDV_20161112T060623_20161112T060648_013905_01661B_ECEF.SAFE</str> 

`

我不想要包含S1Bidentifiertitle的行。例如。在我s1_gg.txt文件中的實際類型的輸出我想:

<str name="filename">S1A_IW_GRDH_1SDV_20161112T060623_20161112T060648_013905_01661B_ECEF.SAFE</str> 
+0

什麼是'grep的 「\ S1A _ \」 開竅了'應該匹配? ESP。那裏有'\ S'? – GhostCat

+0

對於如何從您向我們展示的'fileout'示例中獲取輸出文件,我感到非常困惑。輸出中沒有任何行出現在'fileout'中。請在實例中向我們展示您的數據的相關部分。 – Aserre

+0

我試圖只獲得'S1A',而不是任何包含S,1,A的行,任何順序/位置上的行,該語法可能是錯誤的,但只是「S1A」我得到了與上面相同的結果。 –

回答

1

有幾個缺點在你的腳本:執行後

  • grep掛起,必須由CTRL + C中終結
  • 您的報價非常接近。 \的行爲是爲了逃避以下字符,在特殊字符的情況下將其視爲文字,或者在正常字符的情況下將其視爲字符類。
    • 你寫了"\>而不是\">。當你寫\S\"時,你逃過了字母S和以下"字符。
    • 你應該wirtten:grep "=\"filename\">" | grep "S1A_" | grep "GRDH" fileout >> s1_gg.txt
  • 你通過輸入文件到您的第3 grep電話。
    • 你應該寫:< fileout grep "=\"filename\">" | grep "S1A_" | grep "GRDH" >> s1_gg.txt
    • 這最後修正爲您提供了正確的輸出,解決了grep
+0

感謝您提供有用的反饋。你知道爲什麼類似的命令'」| grep「S1A_」| grep「GRDH」>> s1_gg.txt'不需要/使用'-f'選項來指定它是一個文件? –

+1

''用於文件[重定向重定向](http://www.tldp.org/LDP/abs/html/io-redirection.html)。這意味着重定向的元素是一個文件。 – Aserre

相關問題