Skip to content

Instantly share code, notes, and snippets.

@jag3773
Last active October 23, 2023 19:08
Show Gist options
  • Save jag3773/04459a620619f7a3915b2f4031ca97aa to your computer and use it in GitHub Desktop.
Save jag3773/04459a620619f7a3915b2f4031ca97aa to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
#
# This script downloads the Berean Standard Bible and converts it
# to markdown files for an Obsidian vault.
#
# - Each chapter has it's own file, e.g. "Genesis 1.md"
# - A "Bible.md" index file is also created for navigation.
#
# This will output all files into a subdirectory called BSB.
#
# The script was written and tested on Mac, it should work just as well on Linux.
#
# Copyright 2023 Jesse Griffin, MIT License
# https://opensource.org/license/MIT/
# For mac, make it easier to iterate over file names
IFS=$'\n'
basepath='BSB'
mkdir -p $basepath
indexfile="${basepath}/Bible.md"
echo -e "# Berean Standard Bible\n\n" > "$indexfile"
wget -q https://bereanbible.com/bsb.txt
iconv -f CP1251 -t UTF-8 <bsb.txt >bsb-utf8.txt
for x in `cat bsb-utf8.txt | grep ':'`; do
book_ref=`echo $x | cut -f 1`
ref_num=`echo $x | grep -oE '[0-9]+:[0-9]+'`
book=`echo ${book_ref%%$ref_num} | xargs`
chp=`echo ${ref_num%%:*}`
book_file=`echo ${basepath}/${book} ${chp}.md`
if [ ! -f "$book_file" ]; then
echo -e "# ${book} ${chp}" > "$book_file"
echo -e "## [[${book} ${chp}]]\n" >> "$indexfile"
fi
echo -e "\n###### $ref_num\n" >> "$book_file"
echo "$x" | cut -f 2 >> "$book_file"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment