README: add awk example function to unescape json2tsv output - json2tsv - JSON to TSV converter
HTML git clone git://git.codemadness.org/json2tsv
DIR Log
DIR Files
DIR Refs
DIR README
DIR LICENSE
---
DIR commit a6acda04e4f9f2285e126f7045b83bf7e2f8bf39
DIR parent 84da1dac7041f1fc700cade27c55613a6f900de4
HTML Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Sun, 21 Mar 2021 12:34:54 +0100
README: add awk example function to unescape json2tsv output
Diffstat:
M README | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+), 0 deletions(-)
---
DIR diff --git a/README b/README
@@ -83,6 +83,36 @@ END {
}'
+The following awk function can be used to unescape the json2tsv escape
+sequences \t, \n and \\:
+
+awk '
+BEGIN {
+ FS = OFS = "\t";
+}
+function unescape(s) {
+ for (data = ""; (idx = index(s, "\\")); s = substr(s, idx + 2)) {
+ prev = substr(s, 1, idx - 1)
+ c = substr(s, idx + 1, 1)
+ if (c == "t")
+ data = data prev "\t"
+ else if (c == "n")
+ data = data prev "\n"
+ else if (c == "\\")
+ data = data prev "\\"
+ else
+ data = data prev # ignore other.
+ }
+ return data s # rest
+}
+$2 == "s" && index($3, "\\") {
+ $3 = unescape($3);
+}
+{
+ print $3;
+}'
+
+
License
-------