Skip to content

Instantly share code, notes, and snippets.

@lsloan
Forked from sloanlance/jsonlSort.sh
Created July 13, 2017 17:47
Show Gist options
  • Save lsloan/b6b219370916d39ec1af23cfc74bd6d0 to your computer and use it in GitHub Desktop.
Save lsloan/b6b219370916d39ec1af23cfc74bd6d0 to your computer and use it in GitHub Desktop.
jq, JSON: Sort JSONL by using jq's `--slurp` option to treat it as a JSON array
#!/bin/sh --
# Execute with an argument containing the name of the property to be
# used for sorting.
# Improved according to a suggestion from @pkoppstein in response to my
# support issue:
# https://github.com/stedolan/jq/issues/1447#issuecomment-314918635
jq --slurp --compact-output 'sort_by(.'${1}')[]'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment