14 ms·
For those who want to never learn sed addressing modes, here's a slight cheat using only simpler shell logic. The cheat is to realize you can concatenate multip
by saltcured 5y ago
For those who want to never learn sed addressing modes, here's a slight cheat using only simpler shell logic. The cheat is to realize you can concatenate multiple calls to `cal -1` instead of reshaping the 3x4 grid into 12x1, so just focus on the per-month splicing task...
#!/bin/sh
g() {
read m; read n
[ $1 -eq 1 ] \
&& printf '%20.20s %s\n' "$n" "$m" \
|| printf ' %s %s\n' "$n" "$m"
sed -e 's/ *$/ /'
}
f() {
cal -1 $@ | grep '[0-9]' | g $@ | head -c -1
}
y=${1:-`date +%Y`}
for m in {1..12}; do f $m $y; done
printf "\n"
- deleted 5y ago[deleted]
- Tepix 5y agoOn macOS you have to change it slightly to use the "-m" parameter to cal because it doesn't have the "-1" option.