Last active
January 9, 2026 21:10
-
-
Save sergeiwaigant/f0cf816e143114b6a7d81a901b5d3ce6 to your computer and use it in GitHub Desktop.
Revisions
-
sergeiwaigant revised this gist
Mar 26, 2025 . 1 changed file with 5 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,17 +3,20 @@ Reference https://stackoverflow.com/a/34407620/13287790 ```bash $ printf %s 'encode this'|jq -sRr @uri encode%20this $ jq -rn --arg x 'encode this' '$x|@uri' encode%20this # -r (--raw-output) outputs the raw contents of strings instead of JSON string literals. -n (--null-input) doesn't read input from STDIN. # -R (--raw-input) treats input lines as strings instead of parsing them as JSON, and -sR (--slurp --raw-input) reads the input into a single string. You can replace -sRr with -Rr if your input only contains a single line, or if you don't want to replace linefeeds with %0A: $ printf %s\\n 'multiple lines' 'of text'|jq -Rr @uri multiple%20lines of%20text $ printf %s\\n 'multiple lines' 'of text'|jq -sRr @uri multiple%20lines%0Aof%20text%0A Or this percent-encodes all bytes: xxd -p|tr -d \\n|sed 's/../%&/g' ``` -
sergeiwaigant renamed this gist
Feb 4, 2021 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
sergeiwaigant revised this gist
Feb 4, 2021 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,5 @@ Reference https://stackoverflow.com/a/34407620/13287790 ```bash $ printf %s 'encode this'|jq -sRr @uri encode%20this -
sergeiwaigant renamed this gist
Feb 4, 2021 . 1 changed file with 2 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,5 @@ # Reference https://stackoverflow.com/a/34407620/13287790 ```bash $ printf %s 'encode this'|jq -sRr @uri encode%20this $ jq -rn --arg x 'encode this' '$x|@uri' @@ -17,4 +15,4 @@ $ printf %s\\n 'multiple lines' 'of text'|jq -sRr @uri multiple%20lines%0Aof%20text%0A Or this percent-encodes all bytes: xxd -p|tr -d \\n|sed 's/../%&/g' -
sergeiwaigant created this gist
Feb 4, 2021 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ Another option is to use jq: # Reference https://stackoverflow.com/a/34407620/13287790 $ printf %s 'encode this'|jq -sRr @uri encode%20this $ jq -rn --arg x 'encode this' '$x|@uri' encode%20this -r (--raw-output) outputs the raw contents of strings instead of JSON string literals. -n (--null-input) doesn't read input from STDIN. -R (--raw-input) treats input lines as strings instead of parsing them as JSON, and -sR (--slurp --raw-input) reads the input into a single string. You can replace -sRr with -Rr if your input only contains a single line, or if you don't want to replace linefeeds with %0A: $ printf %s\\n 'multiple lines' 'of text'|jq -Rr @uri multiple%20lines of%20text $ printf %s\\n 'multiple lines' 'of text'|jq -sRr @uri multiple%20lines%0Aof%20text%0A Or this percent-encodes all bytes: xxd -p|tr -d \\n|sed 's/../%&/g'