4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

企業HPソースコードの面白コメントをコマンドライン上で表示

Last updated at Posted at 2021-12-08

問題

企業のHPの中にはソースコードに面白いコメントを記述しているところがあるので、それをコマンドライン上で抽出して表示してみたい。

ルール

  • curl, grepのみ使用
  • -A, -Bなど行数指定や行番号ではなくパターンで抽出
  • 出来るだけ短く

対象


下に自分の解答とスクリーンショットを列挙しています。
自分で腕試ししたい方はここで止めてやってみてください。


自分の解答

実行環境

  • macOS 12.0.1
  • iTerm2 3.4.14
  • zsh 5.8
  • curl 7.77.0
  • grep (GNU grep) 3.7
  • 2021/12/08時点アクセス

Abema

curl -sL abema.tv | grep -o ';;.*;'

image.png

ロリポップ!レンタルサーバー

curl -sL lolipop.jp | grep -ozE '\s+_.*_/.'

image.png

日本・コカコーラ

curl -sL cocacola.co.jp | grep -ozE ' +__.*eux....'

image.png

富士そば

curl -s fujisoba.co.jp | grep -ozE '.  ,.* ̄..'

image.png

食べログ

curl -sL tabelog.com | grep -ozE '\s+z.*t/\s'

image.png

任天堂ニュース

curl -sL nintendo.co.jp/nintendo_news | grep -ozE '<!---.*--->.'

image.png

日本アマゾン

curl -sL amazon.co.jp -A '' | grep -ozE '<!--\s+_.*~-->.'

image.png

ドットインストール

curl -sL dotinstall.com | grep -ozE '\s\[エ.*い。..'

image.png

更新毎にコメント内メッセージが変化する。以下は1秒ごとに画面を更新して取得したコメントを表示するやつ。

while :; do
  echo '\033[2J\033[3J\033[H'
  curl -sL dotinstall.com | grep -ozE '\s\[エ.*い。..'
  sleep 1s
done

GIF↓

_.gif

まとめ

いかがでしたか?笑 grep -ozE、便利です。

4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?