scripts for my gemini capsule
oeb: parse scripref in shell
Zach DeCook 2021-02-25
parent 51c72d5 · commit e7224c7
-rwxr-xr-xoeb.sh15
1 files changed, 10 insertions, 5 deletions
diff --git a/oeb.sh b/oeb.sh
index 15c298a..83568e1 100755
--- a/oeb.sh
+++ b/oeb.sh
@@ -1,10 +1,15 @@
#!/bin/sh
# parse query
-book=John
-chstart=3
-chend=3
-vstart=16
-vend=17
+test "$QUERY_STRING" || QUERY_STRING="$1"
+book=$(echo $QUERY_STRING|cut -d' ' -f1)
+chstart=$(echo $QUERY_STRING|tr ':' ' ' |cut -d' ' -f2)
+vstart=$(echo $QUERY_STRING|tr '-' ':' | cut -d: -f2)
+# vend is always the last number
+vend=$(echo $QUERY_STRING |tr - : |rev|cut -d: -f1|rev)
+# chend is the last leftover
+chend=$(echo $QUERY_STRING|sed "s/$book //"| sed "s/:$vstart-/ /"|sed "s/ \?:\?$vend$//"|rev|cut -d' ' -f1|rev)
+#echo $chstart "\t" $vstart "\t" $chend "\t"$vend && exit
+
file=$(find oeb/ -name '*'-$book'*')
grep '\c '$chstart $file -A500 | grep '\v '$vstart -A500 \
| grep '\c '$(($chend + 1)) -B500 | grep '\v '$vend -B500