[英]Grep every word from a file starting a pattern
因此,我有一個文件稱為“ page.html”。 在此文件中,有一些我要提取的鏈接/文件路徑。 我一直在BASH中嘗試解決這個問題,但似乎做不到。 我想抓住的所有單詞/鏈接/路徑都以“ / funny / hello / there /”開頭。 目標是將所有這些單詞發送到終端,以便我可以使用它們。
到目前為止,這還算是我嘗試過的,沒有運氣:
grep -E '^/funny/hello/there/` page.html
和
grep -Po '/funny/hello/there/.*?` page.html
任何幫助將不勝感激,謝謝。
這是文件中的示例數據:
`<td data-title="Blah" class="Blah" >
<a href="/funny/hello/there/fkljaskdjfl" title="This here">fdsksldjfah</a>
</td>`
我的輸出給了我所有看起來像這樣的不同行:
<a href="/funny/hello/there/fkljaskdjfl" title="This here">fdsksldjfah</a>
盡管“ / fkljaskdjfl”有所不同。
我想要的輸出看起來像:
/funny/hello/there/fkljaskdjfl
/funny/hello/there/kfjasdflas
/funny/hello/there/kdfhakjasa
您可以使用以下grep
命令:
grep -o "/funny/hello/there/[^'\"[:blank:]]*" page.html
但是,應該使用shell
程序實用程序來解析HTML,而應使用專用的HTML dom解析器。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.