Pergunta

I have a URL source page like:

href="http://path/to/file.bz2">german.txt.bz2</a> (2,371,487 bytes)</td>
  <td><a rel="nofollow" class="external text" href="http://a/web/page/">American cities</a></td>
  <td><a rel="nofollow" class="external text" href="http://another/page/to.bz2">us_cities.txt.bz2</a> (77,081 bytes)</td>
  <td><a rel="nofollow" class="external text" href="http://other/page/to/file.bz2">test.txt.bz2</a> (7,158,285 bytes)</td>
  <td>World's largest test password collection!<br />Created by <a rel="nofollow" class="external text" href="http://page/web.com/">Matt Weir</a>

I want use text editors like sed or awk in order to extract exactly pages that have .bz2 at the end of them...

like:

http://path/to/file.bz2
http://another/page/to.bz2
http://other/page/to/file.bz2

Could you help me?

Foi útil?

Solução

Sed and grep:

sed 's/.*href=\"\(.*\)\".*/\1/g' file | grep -oP '.*\.bz2$'

Outras dicas

$ sed -n 's/.*href="\([^"]*\.bz2\)".*/\1/p' file
http://path/to/file.bz2
http://another/page/to.bz2
http://other/page/to/file.bz2

Use a proper parser. For example, using xsh:

open :F html input.html ;
for //a/@href['bz2' = xsh:matches(., '\.bz2$')]
    echo (.) ;
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top