#!/bin/bash # Rough implementation of a command line Reddit comment viewer. # It still needs some work. curl -A "RCV - Reddit Comments Viewer" -s "$1.json" | jq '.[1].data.children[] | recurse(.data.replies.data?.children[]) | .data | "\(.depth):::\(.author):::\(.body)"' | awk -F':::' ' function prefix(n) { pre = "" for (i=1; i<=n; i++) { pre = pre " " } return pre "┃ " } { gsub(/^"/,"") gsub(/"$/,"") pre = prefix(int($1)) gsub(/\\n/,"\n" pre) comment = pre "[" $2 "]:\n" pre $3 "\n" gsub(/[^\n]{80}/,"&\n" pre, comment) print comment }' | less