たいちょーの雑記

ぼくが3日に一度くらい雑記をかくところ

シェル芸160ノック14

9月末に発売されたシェル芸本の続きです。文字コードに突入した。

gihyo.jp

前回はこちら

xztaityozx.hatenablog.com

問題68

$ s=0;t="$(bc <<< 2^100)";while [[ $(bc <<< $t-$s) != 1 ]]; do m=$(bc <<< "($t+$s)/2"); echo $m; date -d @$m && s=$m || t=$m; done
67768036191644399
Wed Dec 31 23:59:59 JST 2147485547

ocsで解こうとしたらパーサーバグってて実行できなかったわ。ガハハ!

問題69

$ curl  https://ja.wikipedia.org/wiki/%E9%96%8F%E7%A7%92 > a
$ cat a | grep -Pe "<t[dh]" | grep -Pe "\d{4}年" -A 4 | sd '.+(\d{4})年.+' '$1' | sd '</?td>' '' | sd '.+(\+1).+' '1'  | grep -vPe "秒|th" | xargs -n3 | awk '$2==1{print $1"/01/01"}$3==1{print $1"/07/01"}'               1972/07/01
1973/01/01
1974/01/01
1975/01/01
1976/01/01
1977/01/01
1978/01/01
1979/01/01
1980/01/01
1981/07/01
1982/07/01
1983/07/01
1985/07/01
1988/01/01
1990/01/01
1991/01/01
1992/07/01
1993/07/01
1994/07/01
1996/01/01
1997/07/01
1999/01/01
2006/01/01
2009/01/01
2012/07/01
2015/07/01
2017/01/01

問題70

$ cat qdata/70/excel_hogan.txt | sd '(.)' '"$1",' | sd '"""' '"\\""' | sd ',$' ''
"エ","ク","セ","ル","方","眼","紙","と","い","う","ど","う","し","よ","う","も","無","い"
"風","習","が","あ","り","ま","す","が","、","我","々","は","文","句","を","言","い","つ"
"つ","も","、","従","わ","ざ","る","を","得","な","い","状","況","に","し","ば","し","ば"
"立","た","さ","れ","ま","す","。","最","後","に","一","言","。"
"\"","N","o"," ","h","o","g","a","n",","," ","n","o"," ","l","i","f","e",".","\""

Excel方眼紙って存在するの?

問題71

$ cat qdata/71/uni.txt | uni i -json | jq -r '.[]|.char+": "+.utf8' | awk '{print $1,NF-1}'
a: 1
±: 2
運: 3
🎂: 4

github.com

問題72

$ echo -e \\U1F3{63,7A}
🍣 🍺

問題73

$ paste <(command ls|grep -av zip) <(command ls | grep -av zip|iconv -f sjis) | xargs -n2 mv
$ ls
ぴーでーえふ.pdf  倒立変態紳士の秘密.txt  秘密の圧縮ファイル.zip

alias ls=exaにしててexaだと文字化けがさらに化けてしまったのでcommandをつけた