Skip to content

Instantly share code, notes, and snippets.

@rev087
Created May 27, 2014 17:19
Show Gist options
  • Save rev087/0dec723e009957432ff6 to your computer and use it in GitHub Desktop.
Save rev087/0dec723e009957432ff6 to your computer and use it in GitHub Desktop.
Command-line reddit search via jq
# Search reddit for a string
redsearch() {
curl "http://www.reddit.com/search.json?q=$1" | jq '[.data.children[].data | {created_utc, permalink, num_comments, ups, author, subreddit, url, title} | select(.title | contains("'$1'"))] | sort_by(.created_utc)'
}
@rev087
Copy link
Author

rev087 commented May 27, 2014

Description

I have this function in my ~/.profile, and use it in the Terminal as redsearch something. Output is pretty-printed, syntax-highlighted JSON, ordered by date. Can be piped to other tools or jq again for further filtering/ordering.

Result

[
  {
    "title": String,
    "url": String,
    "subreddit": String,
    "author": String,
    "ups": Number,
    "num_comments": Number,
    "permalink": String,
    "created_utc": Number
  },
  ...
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment