-
Notifications
You must be signed in to change notification settings - Fork 1
/
expand-table.sh
executable file
·54 lines (38 loc) · 1.06 KB
/
expand-table.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
set -e
[ $# != 5 ] && echo "Usage: ${0##*/} WIDTH..." >&2 && exit 1
while IFS="" read -r LINE; do
read -r CODE <<< "${LINE%%#*}"
[ "$CODE" = "" ] && printf '%s\n' "$LINE" && continue
if [ "$(grep -o '|' <<< "$CODE")" != $'|\n|\n|\n|\n|' ]; then
echo "${0##*/}: not a |||||, line:" >&2
printf '%s\n' "$LINE" >&2
exit 1
fi
IFS="|" read -r COL1 COL2 COL3 COL4 COL5 COL6 <<< "$LINE"
read -r COL1 <<< "$COL1"
read -r COL2 <<< "$COL2"
read -r COL3 <<< "$COL3"
read -r COL4 <<< "$COL4"
read -r COL5 <<< "$COL5"
read -r COL6 <<< "$COL6"
[ -n "$LEN" ] && echo "${#COL1} ${#COL2} ${#COL3} ${#COL4} ${#COL5} ${#COL6}" >&2
( # Because we "shift"
for COL in "$COL1" "$COL2" "$COL3" "$COL4" "$COL5"; do
while [ "${#COL}" -lt "$1" ]; do
COL="$COL "
done
printf '%s' "$COL | "
shift
done
printf '%s\n' "$COL6"
)
if [ "$COL4" = custom ]; then
while :; do
! IFS="" read -r CUSTOM && echo "${0##*/}: cannot read custom line" >&2 && exit 1
[ "$CUSTOM" = "}" ] && break
printf '%s\n' "$CUSTOM"
done
printf '}\n'
fi
done