summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--research/split.sh18
1 files changed, 18 insertions, 0 deletions
diff --git a/research/split.sh b/research/split.sh
new file mode 100644
index 0000000..9a3aed3
--- /dev/null
+++ b/research/split.sh
@@ -0,0 +1,18 @@
+US="$(printf '\037.')"; US="${US%.}"
+
+buf='Hello, world!'
+
+printf '%s' "${buf}" | sed "s/\\(.\\)/\\1${US}/g" | \
+ awk -v FS="${US}" -v j=0 -v squote="'" -v esc_squote="'\\\\''" '
+ {
+ for (i = 1; i <= NF; ++i) {
+ if ($i == "") {
+ continue;
+ }
+ sub(squote, esc_squote, $i);
+ printf("lbufv_%d=" squote "%s" squote "\n",
+ j++, $i);
+ };
+ printf("lbufv_%d=" squote "\n" squote "\n", j++);
+ }
+ '