Webフィードの特殊文字

Webフィードの特殊文字

コマンドラインで私のGmailを確認し、タイトルの最初の35文字を表示するスクリプトを実行しています。

curl -u username:password --silent "https://mail.google.com/mail/feed/atom" | \
grep -oPm1 "(?<=<title>)[^<]+" | sed '1d'|cut -b 1-35

タイトルに'などの特殊文字が含まれていない場合、スクリプトは正しく機能します。&正しく表示されるようにするにはどうすればよいですか?ここで切り取って貼り付けると正しく表示されますが、端末に印刷すると&#39for'&ampforが表示されます&

Up to 93% Off - Valentine&#39;s Day Today&#39;s Deals Live Now:
Michael Vince • FENDI &amp; More for Men

ベストアンサー1

HTMLをデコードする必要があるため、出力をデコーダを介してパイプします。

そしてperl

$ your cammand | perl -MHTML::Entities -le 'while(<>) {print decode_entities($_);}'

例をご覧ください。

$ echo "Ambersand &amp; and Single quote &#39" | perl -MHTML::Entities -le 'while(<>) {print decode_entities($_);}'
Ambersand & and Single quote '

おすすめ記事