Skip to content

Instantly share code, notes, and snippets.

@mutatrum
Created October 6, 2022 08:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mutatrum/71993083af307c8044faaec74d8e4fae to your computer and use it in GitHub Desktop.
Save mutatrum/71993083af307c8044faaec74d8e4fae to your computer and use it in GitHub Desktop.
Define decode_hex function for jq.
def decode_hex:
def decode: if . < 58 then .-48 elif . < 91 then .-55 else .-87 end;
def decode_byte: map(decode) | (.[0] * 16) + .[1];
def pairs: explode | range(0;length;2) as $i | [.[$i], .[$i+1]];
def filter: if (. < 32 or (. >= 128 and . <= 159)) then 46 else . end;
[pairs|decode_byte|filter] | implode;
@mutatrum
Copy link
Author

mutatrum commented Oct 6, 2022

Needs to be placed in ~/.jq/

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