|
1 | 1 | #!/bin/bash |
| 2 | +set -euo pipefail |
2 | 3 |
|
3 | 4 | # create directory if it doesn't exist |
4 | 5 | mkdir -p ../_data/whats_left |
5 | 6 |
|
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 |
8 | 11 |
|
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 |