Skip to content

Instantly share code, notes, and snippets.

@sloanlance
Last active July 13, 2017 18:01
Show Gist options
  • Save sloanlance/e255f15618221af15cd57ac3f55f8aba to your computer and use it in GitHub Desktop.
Save sloanlance/e255f15618221af15cd57ac3f55f8aba to your computer and use it in GitHub Desktop.
jq, JSONL: Use jq's `--slurp` option to treat JSONL as a JSON array, then sort it
#!/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}')[]'
@sloanlance
Copy link
Author

See jq issue: jqlang/jq#1447

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