Skip to content

Instantly share code, notes, and snippets.

@hoel-zr-o
Created May 30, 2025 16:34
Show Gist options
  • Save hoel-zr-o/a04d5f4e59acaf2077ff8c3c3f1e68c6 to your computer and use it in GitHub Desktop.
Save hoel-zr-o/a04d5f4e59acaf2077ff8c3c3f1e68c6 to your computer and use it in GitHub Desktop.
Some jq functions
def parse_duration:
[scan("(?:(\\d+)m)|(?:(\\d+[.]\\d+)s)|(?:(\\d+[.]\\d+)ms)") | (60000 * ((.[0] // "0") | tonumber)) + (1000 * ((.[1] // "0") | tonumber)) + ((.[2] // "0") | tonumber) ] | reduce .[] as $item (0; . + $item) ;
def logfmt:
[ scan("(\\w+)=(?:(?:\"([^\"]+)\")|(\\S+))\\s*") | {key: .[0], value: (.[1] // .[2])}] | from_entries ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment