Skip to content

Commit c621759

Browse files
committed
Rework script to address review comments
1 parent 4178638 commit c621759

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed
Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
11
#!/bin/bash
2+
set -euo pipefail
23

34
# create directory if it doesn't exist
45
mkdir -p ../_data/whats_left
56

6-
# start a new csv file for builtin items
7-
echo "builtin,name,is_inherited" > ../_data/whats_left/builtin_items.csv
7+
# exit violently if the temp file does not exist
8+
if [ ! -f ../_data/whats_left.temp ]; then
9+
exit 1
10+
fi
811

9-
# read the temp file
10-
# in awk:
11-
sed -n '/# builtin items/{n;:a;/^$/q;p;n;ba;}' ../_data/whats_left.temp | \
12-
awk -v OFS=',' '{split($1,a,".");if(index($0,FS)>0){b=substr($0,index($0,FS)+1)}else{b=""};print a[1],$1,b}' >> ../_data/whats_left/builtin_items.csv
12+
# generate the CSV file for builtin items from the temp file
13+
awk -f - ../_data/whats_left.temp > ../_data/whats_left/builtin_items.csv <<'EOF'
14+
BEGIN {
15+
OFS=","
16+
print "builtin,name,is_inherited"
17+
}
18+
/^# builtin items/ { in_section=1; next }
19+
/^$/ { if (in_section) exit }
20+
in_section {
21+
split($1, a, ".")
22+
rest = ""
23+
idx = index($0, " ")
24+
if (idx > 0) {
25+
rest = substr($0, idx+1)
26+
}
27+
print a[1], $1, rest
28+
}
29+
EOF

0 commit comments

Comments
 (0)