LoginSignup
4
8

More than 5 years have passed since last update.

祝日をWebAPIから取得するシェルスクリプトをワンライナーで

Last updated at Posted at 2017-02-05

最近シェル芸人に憧れてシェルの勉強中なのですが、
なんとなくシェルで祝日を取得できたら面白いかな?と思って検索してみたら下記の記事を発見
祝日をWebAPIから取得するシェルスクリプト

awkすごいんだけど読めない...
てことで参考にしてワンライナーで書きなおしてみた。

コード

curl -s https://calendar.google.com/calendar/ical/ja.japanese%23holiday%40group.v.calendar.google.com/public/basic.ics | egrep '^DTSTART|^SUMMARY' | awk -F: '{print $2}' | perl -pe 's/(?<=\d)\r\n/ /m' | sort

実行結果

出力が長いので最後に |head -10 をつけて実行

20160101 元日
20160111 成人の日
20160211 建国記念の日
20160320 春分の日
20160321 春分の日 振替休日
20160429 昭和の日
20160503 憲法記念日
20160504 みどりの日
20160505 こどもの日
20160718 海の日

いい感じで、できてますね

余談

perl で書いた部分はxargsで書く予定だったんですが、マルチバイト文字のせいかうまくいかなかったので、だれか詳しい人に解説して欲しいです...
@kou029wさんのおかげでできました。
こっちのほうが分かりやすいし、perlに依存しないので良いですね(unix系でperlが実行できない環境は珍しいとは思いますが)

xargs版
curl -s https://calendar.google.com/calendar/ical/ja.japanese%23holiday%40group.v.calendar.google.com/public/basic.ics | egrep '^DTSTART|^SUMMARY' | cut -d: -f 2 | tr -d \\r | xargs -L 2 | sort
結果
20160101 元日
20160111 成人の日
20160211 建国記念の日
20160320 春分の日
20160321 春分の日 振替休日
20160429 昭和の日
20160503 憲法記念日
20160504 みどりの日
20160505 こどもの日
20160718 海の日
20160811 山の日
20160919 敬老の日
20160922 秋分の日
20161010 体育の日
20161103 文化の日
20161123 勤労感謝の日
20161223 天皇誕生日
20170101 元日
20170102 元日 振替休日
20170109 成人の日
20170211 建国記念の日
20170320 春分の日
20170429 昭和の日
20170503 憲法記念日
20170504 みどりの日
20170505 こどもの日
20170717 海の日
20170811 山の日
20170918 敬老の日
20170923 秋分の日
20171009 体育の日
20171103 文化の日
20171123 勤労感謝の日
20171223 天皇誕生日
20180101 元日
20180108 成人の日
20180211 建国記念の日
20180212 建国記念の日 振替休日
20180321 春分の日
20180429 昭和の日
20180430 昭和の日 振替休日
20180503 憲法記念日
20180504 みどりの日
20180505 こどもの日
20180716 海の日
20180811 山の日
20180917 敬老の日
20180923 秋分の日
20180924 秋分の日 振替休日
20181008 体育の日
20181103 文化の日
20181123 勤労感謝の日
20181223 天皇誕生日
20181224 天皇誕生日 振替休日

素晴らしい

4
8
4

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
8