parsing data with sed command

0

Minha saída assim:

   <li><a href="/intl/id/download/">Bahasa Indonesia</a></li>
                    <li><a href="/intl/ms/download/">Bahasa Melayu</a></li>
                    <li><a href="/intl/da/download/">Dansk</a></li>
                    <li><a href="/intl/de/download/">Deutsch</a></li>
                    <li><a href="/intl/en/download/">English (US)</a></li>
                    <li><a href="/intl/es/download/">Español</a></li>
                    <li><a href="/intl/es-latam/download/">Español (América Latina)</a></li>
                    <li><a href="/intl/fr/download/">Français</a></li>
                    <li><a href="/intl/it/download/">Italiano</a></li>
                    <li><a href="/intl/nl/download/">Nederlands</a></li>
                    <li><a href="/intl/pl/download/">Polski</a></li>
                    <li><a href="/intl/pt-br/download/">Português (Brasil)</a></li>
                    <li><a href="/intl/pt/download/">Português (Portugal)</a></li>
                    <li><a href="/intl/fi/download/">Suomi</a></li>
                    <li><a href="/intl/sv/download/">Svenska</a></li>
                    <li><a href="/intl/vi/download/">Tiếng Việt</a></li>
                    <li><a href="/intl/tr/download/">Türkçe</a></li>
                    <li><a href="/intl/ru/download/">Русский</a></li>
                    <li><a href="/intl/ar/download/">العربية</a></li>
                    <li><a href="/intl/th/download/">ภาษาไทย</a></li>
                    <li><a href="/intl/ko/download/">한국어</a></li>
                    <li><a href="/intl/zh-cn/download/">中文(简体)</a></li>
                    <li><a href="/intl/zh-tw/download/">中文(繁體)</a></li>
                    <li><a href="/intl/jp/download/">日本語</a></li>
        If your download didn’t start, <a href="https://cdn1.evernote.com/mac-smd/public/Evernote_RELEASE_7.1_456448.dmg">click here</a>.<br>
100 24789  100 24789    0     0  14560      0  0:00:01  0:00:01 --:--:-- 14564
              <li><a href="/get-started">Getting started</a></li>
              <li><a href="/basic">Basic</a></li>
              <li><a href="/premium">Premium</a></li>
              <li><a href="/business">Features</a></li>
              <li><a href="/business/spaces">Spaces<span class="new">New!</span></a></li>
              <li><a href="/business/use-cases">Use cases</a></li>
              <li><a href="/business/customer-stories">Customer stories</a></li>
              <li><a href="/business/contact">Contact sales</a></li>
              <li><a href="http://blog.evernote.com/">Blog</a></li>
              <li><a href="/community">Community</a></li>

Eu quero extrair apenas https://cdn1.evernote.com/mac-smd/public/Evernote_RELEASE_7.1_456448.dmg com o comando sed

    
por Mehran 29.04.2018 / 19:38

2 respostas

0

Apenas com sed como você queria:

sed -n '/cdn1/p' "$YOUR_FILE"| sed 's/^.*\(https.*dmg\).*//g'

Ou mais curto:

sed -n 's/^.*\(https.*dmg\).*//p' "$YOUR_FILE"
sed -n 's/^.*\(https.*\.[a-z]\{2,3\}\).*//p' "$YOUR_FILE"
sed -n 's/^.*\(https\?.*cdn1.*\.[a-z]\{2,3\}\).*//p' "$YOUR_FILE"
    
por 29.04.2018 / 19:55
4

sed e semelhantes NÃO são as ferramentas certas para processar dados XML / HTML.
Use analisadores XML / HTML apropriados, como xmllint ou < strong> xmlstarlet .

Com xmllint você faria:

xmllint --html --xpath 'string(//a[text()="click here"]/@href)' input.html

A saída:

https://cdn1.evernote.com/mac-smd/public/Evernote_RELEASE_7.1_456448.dmg
  • string(//a[text()="click here"]/@href) - a expressão xpath crucial para selecionar a tag cujo valor de texto é click here e obter representação de string de seu atributo href
por 29.04.2018 / 19:54