Automatic Rashi Formatting

First; Format the Verse line:

sed 's/^Verse /==== Verse /g' a > b

Second, encase verse text within HTML tags:

a: add opening tag

sed '/==== Verse/a \<html\>' b > c

b: add closing tag

sed -e ':a' -e 'N' -e '$!ba' -e 's/\n\n==== Verse/\<\/html\>\n\n==== Verse/g' c > d

c: fix spacing between tag and <b> (not working yet)

sed -e ':a' -e 'N' -e '$!ba' -e 's/\n\n<b>/<b>/g' d > e

Third, clean up empty verses

sed -e ':a' -e 'N' -e '$!ba' -e 's/<html>\n\n<\/html>//g' e > f

sed -e ':a' -e 'N' -e '$!ba' -e 's/==== Verse .\n\n\n//g' f > g

sed -e ':a' -e 'N' -e '$!ba' -e 's/==== Verse ..\n\n\n//g' g > h

Shell Script

Here’s a shell-script for it, considering that the chapter text is in ‘a’:

#!/bin/sh
sed 's/^Verse /==== Verse /g' a > b
sed '/==== Verse/a \<html\>' b > c
sed -e ':a' -e 'N' -e '$!ba' -e 's/\n\n==== Verse/\<\/html\>\n\n==== Verse/g' c > d
sed -e ':a' -e 'N' -e '$!ba' -e 's/\n\n<b>/<b>/g' d > e
sed -e ':a' -e 'N' -e '$!ba' -e 's/<html>\n\n<\/html>//g' e > f
sed -e ':a' -e 'N' -e '$!ba' -e 's/==== Verse .\n\n\n//g' f > g
sed -e ':a' -e 'N' -e '$!ba' -e 's/==== Verse ..\n\n\n//g' g > h
rm a b c d e f g

Finally, separate file into chapters AND attach it to the end of a file

sed -n '/^Chapter.1$/,/^Chapter.2$/p' h >> ch1.txt

(or even, if you are just pulling from the middle)

sed -n '/^Chapter.1$/,/^Chapter.2$/p' h | tail -n +5 | head -n -2 >> ch1.txt

Leave a Reply

Your email address will not be published.