i---------------------------------------- | |
iawk is the best | |
iJanuary 23rd, 2018 | |
i---------------------------------------- | |
i | |
iI have a section on this phlog called "Current Books" [0]. That is | |
ithe output of a cgi script that queries my Goodreads reading list | |
ivia RSS, selects the relevant data, formats and displays it. | |
i | |
iThis is the heart of that script. It's 1 line of code. | |
i | |
i(Fake linebreaks for easy reading) | |
i | |
icurl -s "<RSS FEED>" | | |
i /usr/pkg/bin/xml sel | |
i -t | |
i -m "/rss/channel/item" | |
i -v "title" | |
i -o "^" | |
i -v "author_name" | |
i -o "^" | |
i -v "book/num_pages" -n | | |
i | |
i awk 'BEGIN { | |
i FS="^"; | |
i books="\n"; | |
i print "Books I am currently reading:" | |
i } | |
i | |
i $3 ~ /[0-9]+/ { | |
i pages+=$3; | |
i books=(books $1 "\n by " $2 "\n") | |
i } | |
i | |
i END { | |
i print "(" pages " pages left to read)\n", books | |
i }' | | |
i | |
i fold -s -w 66 > | |
i "/sdf/arpa/tz/t/tomasino/gopher/reading/currentbooks.txt" | |
i | |
iI love awk and I don't get to use it nearly enough. | |
i | |
[0] Currently Reading |