Created
October 6, 2022 08:12
-
-
Save mutatrum/71993083af307c8044faaec74d8e4fae to your computer and use it in GitHub Desktop.
Define decode_hex function for jq.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Needs to be placed in
~/.jq/