次の場合、すべてのタグをどのように削除できますか?
Study eases concerns about taking antidepressants during pregnancy and autism risk <a href="https://t.co/Cs0mdeYEBo" rel="nofollow noopener" dir="ltr" data-expanded-url="http://cbsn.ws/2oTosqU" class="twitter-timeline-link" target="_blank" title="http://cbsn.ws/2oTosqU" ><span class="tco-ellipsis"></span><span class="invisible">http://</span><span class="js-display-url">cbsn.ws/2oTosqU</span><span class="invisible"></span><span class="tco-ellipsis"><span class="invisible"> </span></span></a><a href="https://t.co/rs5813GdLG" class="twitter-timeline-link u-hidden" data-pre-embedded="true" dir="ltr" >pic.twitter.com/rs5813GdLG</a>
このコマンドを使用した後の結果は、次のようになります。
Study eases concerns about taking antidepressants during pregnancy and autism risk
以下を使用した後:
sed -e 's/<[^>]*>//g'
または
sed 's/<[^>]\+>//g'
私は得る:
Study eases concerns about taking antidepressants during pregnancy and autism risk http://cbsn.ws/2oTosqU pic.twitter.com/rs5813GdLG
これは私が望むものではありません。これを行うには、sed、awk、grepを使用する必要があります。
ベストアンサー1
コマンドは正しく機能しますが、ファイル形式が正しくありません。grep --color=yes <[^>]*>' file
各項目の後に改行文字を追加すると、それを使用または表示できます>
。
$ sed -e 's/>/>\n/g' file
Study eases concerns about taking antidepressants during pregnancy and autism risk <a href="https://t.co/Cs0mdeYEBo" rel="nofollow noopener" dir="ltr" data-expanded-url="http://cbsn.ws/2oTosqU" class="twitter-timeline-link" target="_blank" title="http://cbsn.ws/2oTosqU" >
<span class="tco-ellipsis">
</span>
<span class="invisible">
http://</span>
<span class="js-display-url">
cbsn.ws/2oTosqU</span>
<span class="invisible">
</span>
<span class="tco-ellipsis">
<span class="invisible">
</span>
</span>
</a>
<a href="https://t.co/rs5813GdLG" class="twitter-timeline-link u-hidden" data-pre-embedded="true" dir="ltr" >
pic.twitter.com/rs5813GdLG</a>
http://</span>
、、、cbsn.ws/2oTosqU
および
はhtmlタグ内にないため、そのまま残り、pic.twitter.com/rs5813GdLG
これは非常に正確です。
したがって、必要なのはhtmlタグを削除することではありません。そして他のものもしかし、私はあなたが望むものと望まないものが何であるかを知る方法がわかりません。