summaryrefslogtreecommitdiffstats
path: root/research/split.sh
blob: 9a3aed37dd781d1a88e65a128ea638a9f9be524d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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++);
	}
	'