From b2faec3952a89b354c815a782efb5df2cc728b91 Mon Sep 17 00:00:00 2001 From: Stefaan Lippens Date: Sat, 20 Jun 2015 23:40:12 +0200 Subject: [PATCH] taocl "fortune" function: use python oneliner instead of dependency on non-standard tools (pandoc and xmlstarlet) --- README.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index edad6fd..823f2d9 100644 --- a/README.md +++ b/README.md @@ -289,14 +289,11 @@ A few examples of piecing together commands: cat access.log | egrep -o 'acct_id=[0-9]+' | cut -d= -f2 | sort | uniq -c | sort -rn ``` -- Run this function to get a random tip from this document (parses Markdown and extracts an item): +- Run this function to get a random tip from this document: ```sh function taocl() { curl -s https://raw.githubusercontent.com/jlevy/the-art-of-command-line/master/README.md | - pandoc -f markdown -t html | - xmlstarlet fo --html --dropdtd | - xmlstarlet sel -t -v "(html/body/ul/li[count(p)>0])[$RANDOM mod last()+1]" | - xmlstarlet unesc | fmt -80 + python -c 'import sys,re,random;print random.choice([m.group(1) for m in re.finditer(r"^- (.*?)\n\n",sys.stdin.read(),re.DOTALL|re.MULTILINE)])' | fmt -80 } ```