# flatten.awk version 2 by Ben Collver # # This is a one-off script to convert the Mind Expanding Books list # to a plain text document. It depends on webdump. It uses the # strftime() function, which is present in busybox, gawk, and mawk. # # webdump # # Usage: # # URL=https://project-awesome.org/hackerkid/Mind-Expanding-Books # curl -S $URL | webdump | mawk -f flatten.awk >list.txt # print_wrap() will break long lines into line continuations function print_wrap(str, len) { line = 1 buf = str while (length(buf) > len) { chunk = substr(buf, 1, len) if (match(chunk, / [^ ]*$/)) { before = substr(buf, 1, RSTART-1) after = substr(buf, RSTART+1) if (line == 1) { print before } else { print " " before } buf = after } else { break } line++ } if (line == 1) { print buf } else { print " " buf } } BEGIN { FS = "\t" mode = "text" head[1] = "Name" head[2] = "Author" head[3] = "Rating" head[4] = "Year" } /^ Name \tAuthor \tGoodreads Rating \tYear Published $/ { mode = "flatten" next } /^$/ { mode = "text" } { if (mode == "text") { print_wrap($0, 70) } else if (mode == "flatten") { for (i = 1; i < 5; i++) { gsub(/^ */, "", $i) gsub(/ *$/, "", $i) if (length($i) < 63) { printf "%-7s %s\n", head[i] ":", $i } else { print head[i] ":" print_wrap(" " $i, 70) } } printf "\n" } else { exit 1 } } END { print "" print "Last updated: " strftime("%Y-%m-%d") }