g | x | w | all
Bytes Lang Time Link
nanI have write a web to generate random bible verse250315T075004Zzyang
066Jelly231121T211417ZNick Ken
216JavaScript ES6231121T210243ZArnauld
283GNU sed En231121T220045ZPhilippo

I have write a web to generate random bible verse , You can check it.

Jelly, 80 # Jelly, 66 bytes

ḢfØDV+2ị=”JƲo1
Ḳ-ị⁹œṣ⁷x5¤¤ỴḢwɗƇị@Ç{ỴKḲ<”AȦ$€œṗ$Ḣ⁼¥ƇḲṪ¹⁾1:;$f?”:ʋḢK

Try it online!

A pair of links that is called as a dyad and that takes the pg10.txt file as its right argument and the required biblical reference as its left argument. TIO fails with the full document (presumably because the POST exceeds the maximum size), and the links to TIO on CGCC are even more limited because of length. However, it should work with the full text if run locally.

Pleasingly now code length in bytes == number of books in bible.

Explanation (outdated)

ḢfØDV+2ị=”JƲo1                                          # Helper link: Takes a bible reference and returns which number book should be used that matches the textual part of the reference; half the code is to handle the John letters
Ḣ                                                       # Head
 fØD                                                    # Keep only digits
    V                                                   # Evaluate (will be 0 if no digits)
     +     Ʋ                                            # Add the result of the following, applied to the helper link's original argument
      2ị=”J                                             # - 1 if the second remaining character is a J, otherwise 0
            o1                                          # Or 1 (replaces 0s with ones)

Ḳ-ị⁹œṣ”¶x5¤¤Ỵ€¤Ḣw¥Ƈị@Ç{KœṣḲṪ¹⁾1:;$f?”:ʋ2ịwⱮØD;€”:¤œPƊḢḊ # Main link: takes a bible reference as its argument and returns the verse
Ḳ                                                       # Split at spaces
 -ị                                                     # Penultimate part (will be the last word of the book title)
   ⁹          ¤                                         # Using the following applied to the right argument:
    œṣ”¶x5¤¤                                            # - Split at five consecutive newlines
            Ỵ€                                          # - Split each at newlines
               Ḣw¥Ƈ                                     # Keep those where the first line includes the book title word from earlier
                   ị@Ç{                                 # Index into this using the result of calling the helper link on the original reference (so returning a single book)
                       K                                # Join with spaces
                        œṣ            Ʋ                 # Split at the substring determined by calling following on the original reference:
                          Ḳ                             # - Split at spaces
                           Ṫ                            # - Tail (i.e. the verse or chapter:verse)
                                  f?”:                  # - If contains a colon:
                            ¹                           #   - Leave as is
                             ⁾1:;$                      #   - Else: prepend "1:"
                                       2ị               # Take the second part (i.e. the bit immediately after the chapter:verse reference)
                                                    Ɗ   # Following as a monad:
                                         wⱮØD;€”:¤      # - Find the position of every sublist that comprises of a digit followed by a colon
                                                  œP    # - And split at these
                                                     ḢḊ # Take the first remaining part, and then remove the first character (which will be the space left just after the original chapter:verse marker)
💎

Created with the help of Luminespire.

JavaScript (ES6), 216 bytes

Expects (text)(reference).

t=>s=>([,s,v]=s[M='match'](/(.+) (.+)/),t.split(/\*+|[\r\n]{10}/)[(n=t.split`
`.findIndex(r=>r[M](s.replace(/\d/,n=>` ${"_FST"[n]}.* .*`))))?n-21:64]+0)[M]((v[1]?v:"1:"+v)+"([^]*?)\\d")[1].trim().replace(/\r\n/g," ")

Try it online!

(The TIO code works on a small extract of the original file.)

Method

  1. We compute the book number by looking for the line containing the book name in the summary. There's a special case for James which appears on the very first line of the file. We also have to be careful about the misalignment between Malachi and Matthew.
  2. We split the text and extract the relevant book.
  3. We look for the requested verse in this book and format it.

Commented

t =>                    // t = input text
s =>                    // s = reference
(                       //
  [, s, v] = s.match(   // split s into:
    /(.+) (.+)/         //   s = book name
  ),                    //   v = "chapter:verse" or just "verse"
  t.split(              // turn t into an array of books
    /\*+|[\r\n]{10}/    // by splitting on "***" or "\r\n" * 5
  )[(                   //
    n = t.split`\n`     // split t on new lines
      .findIndex(r =>   // and find the first string r
        r.match(        //   which contains:
          s.replace(    //     the book name
            /\d/, n =>  //       with the leading digit (if any)
            " " +       //       replaced with a space
            "_FST"[n] + //       followed by "F", "S" or "T"
                        //       (for "First", "Second", "Third")
            ".* .*"     //       followed by ".* .*"
          )             //     end of replace()
        )               //   end of match()
      )                 // end of findIndex()
  ) ?                   // if n is not 0:
    n - 21              //   use n - 21
  :                     // else:
    64                  //   use 64 for "James"
  ] + 0                 // get the n-th book and append a "0"
).match(                // then find:
  (v[1] ? v : "1:" + v) //   the verse header,
  + "([^]*?)"           //   followed by the verse content,
  + "\\d"               //   followed by a trailing digit
)[1]                    // end of match(); keep the content
.trim()                 // trim it
.replace(/\r\n/g, " ")  // and turn line breaks into spaces

GNU sed -En:  330 321 303 298  283 bytes

The reference is given in the first line. In real life you can do this like sed 'the script' <<(echo Luke 19:10;cat pg10.txt)

1{s/^([123]) /\1/;s/.* S/S/;/:/!s/ / 1:/;h}
/\n/!N;N;/^.{5}$/!D;n;n;s/\r//;/Bi/D
/Ac|La|Re/s/ of.*// 
s/The Fi/1/;s/The Se/2/;s/The Th/3/;s/^[123].*M//
s/[^0-9]* //;s/ms$/m/;G;/^(..*)\n\1/!d
:1
n;G;/(.*:.*) .*\n.* \1$/!b1
s/\n.*//;s/.*[0-9]:\S* //
:2
N;/ *[0-9]*[:*]\S.*/!b2
s///;s/\r\n/ /gp

Explanation: The first line forms the given verse to remove the whitespace after a number, rename the Song of Salomon and add 1: for one-chapter books; this gets saved in the hold space. The second line finds book titles, the following three convert them to a canonical form and check for a match with the given verse. The rest of the script search for the exact verse inside the book and strip it to only that verse.

This was the original POSIX sed -n version with 298 bytes:

1{s/^\([123]\) /\1/;s/.* S/S/;/:/!s/ / 1:/;h;}
/\n/!N;N;/^.....$/!D;n;n;s/^M//;/Bi/D
/[ALR][cae]/s/ of.*//
s/The F/1/;s/The Se/2/;s/The T/3/;s/^[123].*M//
s/[^0-9]* //;s/ms$/m/;G;/^\(..*\)\n\1/!d
:1
n;G;/\(.*:.*\) .*\n.* \1$/!b1
s/\n.*//;s/.*[0-9]:[^ ]* //
:2
N;/ *[0-9]*[:*][^ ].*/!b2
s///;s/^M\n/ /g;p