如何从输出中grep并将greped文本写入fille

时间:2015-08-27 17:30:41

标签: bash shell grep

我想只在每个http:行之后使用grep文本并将其写入文件。 我有输出流的当前输出

<table style="margin: 5px 15px; 5px 20px;" align="center" bgcolor="#666666" border="0" cellpadding="3" cellspacing="1">
    <tbody><tr style="background: #04C1DE; font-family: Verdana; font-weight: bold; font-size: 18px;">
      <td style="width: 50%; padding: 5px;">
        Word
    </td>
      <td style="width: 20%; padding: 5px;">
        Author
      </td>
      <td style="width: 10%; padding: 5px;">
        Date
      </td>
      <td>Category</td>
        <td>Active?</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
    </tr>
  </tbody>

    </tr>

  <?php
  $count = 1;
    $bgc = 0;


  while($row = mysql_fetch_array($sql))
  {
    if ($count > 100) break;
    echo '<tr style="background: ';
        if ($bgc==0) echo "#FFFFFF";
        else echo "#CFEBFD";
        $bgc == 0?$bgc=1:$bgc=0;
    echo ';">';
    echo "<td><a href=../../words/display_word.php?ID=$row[ID]>$row[Title]</a></td>";
    echo "<td>$row[Author]</td><td>$row[Display_Date]</td><td>$row[category]</td>";
    if($row[active])
    {
      echo "<td>YES</td>";
    }
    else
    {
      echo "<td>NO</td>";
    }
    echo "<td>$row[link_count]</td>";
    if($row[Title] != "")
    {
      echo "<td><a href=words_edit.html?ID=$row[ID]>Edit</a></td></tr>";
    }
    else
    {
      echo "</tr>";
    }
    $count++;
  }
 ?>

我目前没有greping的代码在

之下
References

   1. https://soundcloud.com/sc-opensearch.xml
   2. https://m.soundcloud.com/search/sounds?q=L AME IMMORTELLE
   3. https://soundcloud.com/
   4. http://www.enable-javascript.com/
   5. https://soundcloud.com/search
   6. https://soundcloud.com/search/sounds
   7. https://soundcloud.com/search/sets
   8. https://soundcloud.com/search/people
   9. https://soundcloud.com/search/groups
  10. https://soundcloud.com/thomas-rainer/l-ame-immortelle-banish
  11. https://soundcloud.com/outtamyndxmetal-llc/lame-immortelle-the-heart
  12. https://soundcloud.com/cyberdelic-mind/l-me-immortelle-dark-mix-i
  13. https://soundcloud.com/sawthinzarhtaik/dort-drauben
  14. https://soundcloud.com/lagrima-negra/lagrima-tears-in-the-rain
  15. https://soundcloud.com/bathony/in-strict-confidence-zauberschlos-lame-immortelle-version
  16. https://soundcloud.com/jubej-thos/sirius-5-jahre-lame-immortelle
  17. https://soundcloud.com/virul3nt/lamme-immortelle-sag-mir-wann-shiv-r-remix
  18. https://soundcloud.com/outtamyndxmetal-llc/lame-immortelle-no-goodbye
  19. https://soundcloud.com/usefulrage/das-ich-dem-ich-den-traum
  20. http://help.soundcloud.com/customer/portal/articles/552882-the-site-won-t-load-for-me-all-i-see-is-the-soundcloud-logo-what-can-i-do-
  21. http://google.com/chrome
  22. http://firefox.com/
  23. http://apple.com/safari
  24. http://windows.microsoft.com/ie
  25. http://help.soundcloud.com/

2 个答案:

答案 0 :(得分:1)

您可以使用grep -E

grep -i -oE 'https?://soundcloud\.com[^[:blank:]]*'

答案 1 :(得分:0)

它适用于

&#13;
&#13;
lynx --dump -listonly https://soundcloud.com/search/sounds?q=L%20AME%20IMMORTELLE | \
    tr "\t\r\n'" '   "' | \
    grep -i -oE 'https?://[^[:blank:]]+' | \
    sed -e 's/^.*"\([^"]\+\)".*$/\1/g' \
>k.txt
&#13;
&#13;
&#13;

我得到了合适的输出

&#13;
&#13;
https://soundcloud.com/sc-opensearch.xml
https://m.soundcloud.com/search/sounds?q=L
https://soundcloud.com/
http://www.enable-javascript.com/
https://soundcloud.com/search
https://soundcloud.com/search/sounds
https://soundcloud.com/search/sets
https://soundcloud.com/search/people
https://soundcloud.com/search/groups
https://soundcloud.com/thomas-rainer/l-ame-immortelle-banish
https://soundcloud.com/outtamyndxmetal-llc/lame-immortelle-the-heart
https://soundcloud.com/cyberdelic-mind/l-me-immortelle-dark-mix-i
https://soundcloud.com/sawthinzarhtaik/dort-drauben
https://soundcloud.com/lagrima-negra/lagrima-tears-in-the-rain
https://soundcloud.com/bathony/in-strict-confidence-zauberschlos-lame-immortelle-version
https://soundcloud.com/jubej-thos/sirius-5-jahre-lame-immortelle
https://soundcloud.com/virul3nt/lamme-immortelle-sag-mir-wann-shiv-r-remix
https://soundcloud.com/outtamyndxmetal-llc/lame-immortelle-no-goodbye
https://soundcloud.com/usefulrage/das-ich-dem-ich-den-traum
http://help.soundcloud.com/customer/portal/articles/552882-the-site-won-t-load-for-me-all-i-see-is-the-soundcloud-logo-what-can-i-do-
http://google.com/chrome
http://firefox.com/
http://apple.com/safari
http://windows.microsoft.com/ie
http://help.soundcloud.com/
&#13;
&#13;
&#13;