2011-12-16 25 views
0

我正在編寫一個bash腳本,它將下載頁面,然後搜索jpg鏈接並下載它們。我遇到了grep/sed命令,無法讓他們找到鏈接。到目前爲止,我已經試過:如何在linux中從string1搜索到string2?

grep -e "http.*" -e ".*jpg" -n wget.html 

sed -n '/http/,/jpg/p' wget.html 

如何從搜索HTTP://爲JPG在Linux?或者,除了sed,grep還有其他的方法嗎?

+0

grep的 - e「http。*」-e「。* jpg」-n wget.html和sed -n'/ filmix /,/ jpg/p'wget.html – 2011-12-16 19:24:00

+0

bash不是一個很好的工具 – Daenyth 2011-12-16 19:27:56

回答

1

據我所知,你想從一些下載的HTML中提取所有http://...jpg字符串。我想最好每行一個。

$ cat wget.html | grep -e 'http:.*jpg' |sed -e 's/^.*\(http:.*jpg\).*$/\1/g' 

grep只挑出包含http refs的行,sed從這些行中刪除所有其他的垃圾。

這僅限於每個HTML行的一個http ref。如果不能假設,你可以在管道的開頭添加類似「TR‘>’‘\ 010’分裂線,多個標籤

例:

sal-xps:~ $ cat wget.html 
<body> 
<img src="http://foo.jpg"> 
<img src="http://bar/gronk.jpg"> 
</body> 


sal-xps:~ $ cat wget.html | grep -e 'http:.*jpg' |sed -e 's/^.*\(http:.*jpg\).*$/\1/g' 
http://foo.jpg 
http://bar/gronk.jpg 
相關問題