9月末に発売されたシェル芸本の続きです。
前回はこちら
問題57
$ cat qdata/57/table.md | sd '\|' ' | ' | column -t | sd ' ?\| ?' '|' | AAA | BBB | CCC | | --- | --- | --- | | 1 | 123 | 4 | | 10000 | 1 | 64 | | 3 | 3 | 3 |
pandoc
解は楽でいいのでpandoc
も使っていきます
問題58
$ cat qdata/58/num.csv | teip -og '"([\d]+,?)+"' -- sd ',' '' | tr -d \" | tr , + | paste -sd + | bc 1235362.19999999999999999999999
teipは便利だなあ
問題59
$ cat qdata/59/data.csv| awk '{print NR","$0}' |rb -l 'require "csv";a=CSV.parse(self)[0];if(a.length == 3) then pp a; end' | grep "\[" | tr -d '\[\]\\' "4", "もう,",", "いや,",や"
ruby芸も覚えたいね
問題60
$ dateutils.dseq --format "%Y-%m %d" 2017-02-24 7d 2017-12-31 | awk '{a[$1]=$2}END{for(k in a) print k"-"a[k]}' | sort 2017-02-24 2017-03-31 2017-04-28 2017-05-26 2017-06-30 2017-07-28 2017-08-25 2017-09-29 2017-10-27 2017-11-24 2017-12-29
問題61
$ dateutils.dseq --format "%Y-%m-%d" "$(date -d $((1+$(date +%w))) +%F)" -1d $(date -d "$((7+$(date +%w))) day ago" +%F) | grep -f- <(exa --time-style=long-iso -l|sel 4:) 2021-11-28 00:00 2021-11-28_00:00:00 2021-11-28 01:00 2021-11-28_01:00:00 2021-11-28 02:00 2021-11-28_02:00:00 2021-11-28 03:00 2021-11-28_03:00:00 2021-11-28 04:00 2021-11-28_04:00:00 2021-11-28 05:00 2021-11-28_05:00:00 2021-11-28 06:00 2021-11-28_06:00:00 ...
問題62
$ uconv -f sjis qdata/62/syukujitsu.csv | awk -F'[/,]' '/2019/,0{printf "%d/%02d/%02d %s\n",$1,$2,$3,$4}' | join - <(dateutils.dseq 2019-01-01 2021-12-31 --format "%Y/%m/%d") -a 2 | awk '$2=NF==1?"@":$2' OFS=, | head 2019/01/01,元日 2019/01/02,@ 2019/01/03,@ 2019/01/04,@ 2019/01/05,@ 2019/01/06,@ 2019/01/07,@ 2019/01/08,@ 2019/01/09,@ 2019/01/10,@ ...