Title:
tao
Authors:
skingrapher
Date:
Id:
fhf75e

/usr/bin/env oksh

Generates a fortune file of Ursula K. Le Guin's

edition of the Dao De Jing

Thanks to Nicholas Bennett/lovingawareness for

transcribing the original text to markdown.

U="https://raw.githubusercontent.com/lovingawareness/tao-te-ching/master/Ursula%20K%20Le%20Guin.md" T=$(mktemp) trap "rm -f $T" EXIT O=ddj.txt alias P='cat -s' function H { head -$1 $2 } function L { grep -n "$1" $T|cut -d: -f1|H 1 } function C { H $1 $3|tail -$2 } function S { sed -e 's/##? //g;s/^[[:space:]]+//' $1|tr -s '%' } [ -f $T ]&&curl -s $U>$T||exit 1 l=$(L '# 1') for i in $(seq 2 82);do ol=$l l=$([ $i -lt 82 ]&&L "# $i"||L '# Note') ((h=$l-1)) ((t=$l-$ol)) c=$(C $h $t $T|L '>') [ $c -gt 0 ]&&((c=$c-1))&&C $h $t $T|H $c|S|P>>$O||C $h $t $tmp|S|P>>$O [ $i -lt 82 ]&&print %>>$O done