我正在尝试搜索文件列表以在一行中包含此信息:
<filename>
S1A_
GRDH
。但是,当我使用下面的命令时,除了我想要的行之外,我得到的行不包含此信息
$ grep "=\"filename"\>" | grep "\S1A_\" | grep "GRDH" fileout >> s1_gg.txt
fileout示例:
<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"><gml:Polygon srsName="http://www.opengis.net/gml/srs/epsg.xml#4326" xmlns:gml="http://www.opengis.net/gml">
<gml:outerBoundaryIs>
<gml:LinearRing>
<gml:coordinates>51.329529,5.606034 51.745312,1.813976 53.240158,2.187638 52.821747,6.108649 51.329529,5.606034</gml:coordinates>
</gml:LinearRing>
</gml:outerBoundaryIs>
</gml:Polygon></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"><gml:Polygon srsName="http://www.opengis.net/gml/srs/epsg.xml#4326" xmlns:gml="http://www.opengis.net/gml">
<gml:outerBoundaryIs>
<gml:LinearRing>
<gml:coordinates>50.937958,3.404580 51.348900,-0.315099 52.843983,0.056133 52.430630,3.900550 50.937958,3.404580</gml:coordinates>
</gml:LinearRing>
</gml:outerBoundaryIs>
</gml:Polygon></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>
`
我不希望包含S1B
或identifier
或title
的行。例如。我想要在s1_gg.txt
文件中输出的实际输出类型:
<str name="filename">S1A_IW_GRDH_1SDV_20161112T060623_20161112T060648_013905_01661B_ECEF.SAFE</str>
答案 0 :(得分:1)
你的剧本有几个缺陷:
grep
在执行后挂起,必须由 CTRL + C \
的行为是为了转义下面的字符,在特殊字符的情况下将其视为文字,或者在普通字符的情况下视为字符类。
"\>
而不是\">
。您在撰写S
时转义了"
字母和以下\S\"
字符。grep "=\"filename\">" | grep "S1A_" | grep "GRDH" fileout >> s1_gg.txt
grep
来电。
< fileout grep "=\"filename\">" | grep "S1A_" | grep "GRDH" >> s1_gg.txt
grep