Page 1 of 1
Referencing Bible Verses Individually
Posted: 08 Jan 2011 06:20
by mosquitochalkie
I am unsure whether this is the correct forum, if it is not, I apologize in advance.
I have a text file of the entire bible in which each verse is a separate paragraph which begins with the number of the verse and each chapter has a heading of the name of the book and the chapter number.
ie. Genesis 1
1 In the beginning . . . .
2 the earth was . . .
3 etc etc
Genesis 2
1 Thus the heavens . . .
2 etc etc
Exodus 1
1 Now these are the names . . . .
I wish to organize the file so that the whole reference precedes each verse
ie. Genesis 1:1 In the beginning . . . .
Genesis 1:2 the earth was . . . . etc.
If anybody knows any way that this can be done, either through DOS commands, batch files, third party programs or whatever, I would be most grateful.
Thank you all.
Re: Referencing Bible Verses Individually
Posted: 08 Jan 2011 07:48
by !k
Mmm...
Code: Select all
@echo off
for /f "tokens=1,* delims=]" %%a in ('find /n /v "" %1') do call :sub "%%b"
goto :eof
:sub
for /f "delims=" %%c in ('echo.%~1^| findstr /rc:[0-9]$') do set "chap=%%c"
if "%~1"=="" echo.
if "%chap%"=="%~1" echo.%chap%
if not "%~1"=="" if not "%chap%"=="%~1" echo.%chap%:%~1
goto :eof
Use
Re: Referencing Bible Verses Individually
Posted: 08 Jan 2011 08:40
by ghostmachine4
download
gawk for windows, and use this one liner
Code: Select all
C:\test>more file
Genesis 1
1 In the beginning . . . .
2 the earth was . . .
3 etc etc
Genesis 2
1 Thus the heavens . . .
2 etc etc
Exodus 1
1 Now these are the name
C:\test>gawk "/^[A-Z]/{s=$0;}/^[0-9]/{print s\".\"$0 }" file
Genesis 1.1 In the beginning . . . .
Genesis 1.2 the earth was . . .
Genesis 1.3 etc etc
Genesis 2.1 Thus the heavens . . .
Genesis 2.2 etc etc
Exodus 1.1 Now these are the name
Note: It will be many times faster than any batch that calls too many find/findstr process.
Re: Referencing Bible Verses Individually
Posted: 08 Jan 2011 08:51
by ghostmachine4
!k wrote:Mmm...
Code: Select all
@echo off
for /f "tokens=1,* delims=]" %%a in ('find /n /v "" %1') do call :sub "%%b"
goto :eof
:sub
for /f "delims=" %%c in ('echo.%~1^| findstr /rc:[0-9]$') do set "chap=%%c"
if "%~1"=="" echo.
if "%chap%"=="%~1" echo.%chap%
if not "%~1"=="" if not "%chap%"=="%~1" echo.%chap%:%~1
goto :eof
Use
1) slow, for each line in the file, you are invoking extra findstr process. Its an entire bible verse. for a large file , this will take "forever"
2) when i run the script, extra header generated
Re: Referencing Bible Verses Individually
Posted: 08 Jan 2011 09:05
by mosquitochalkie
Thank you very much for this !k. Your code works well but there are two problems 1) it only did 4 out of 1189 chapters and 2) there are periodic sub-headings on their own lines within each chapter as well and your code places the 'book and chapter' in front of them too.
Thank you again for your time. I have been burning midnight oil for a week trying to make this thing work and didn't get anywhere near as far as you did in about half an hour. You have shown me that it can be done.
If you can solve the two 'problems' that would be great, but I understand if you do not have time. I will work with the code you have given me and see what I can come up with.
By the way, I am using Win7 if that makes a difference.
Re: Referencing Bible Verses Individually
Posted: 08 Jan 2011 09:21
by mosquitochalkie
I apologize ghostmachine4, I called you !k in my reply to you. I understand that on such a large file it would take a long time but why would it just cut out after 4 verses. Could this be a memory problem? Should I break the file up into smaller chunks? I did not understand your reply to problem 2. Maybe I was not clear. Apart from the book and chapter number at the beginning of each chapter there are also sub-headings in the original text. These sub-headings do not need to have the book and chapter put in front of them. They need to be overlooked somehow.
Thank you again. And for your speedy replies as well.
mosquitochalkie
Re: Referencing Bible Verses Individually
Posted: 08 Jan 2011 09:49
by ghostmachine4
then you will have to provide a more concrete example of your verses...I am only working with your provided sample...I am not a psychic to know what exactly is the format of your text.
Re: Referencing Bible Verses Individually
Posted: 09 Jan 2011 00:28
by mosquitochalkie
Actual text follows
Genesis 1
The Beginning-Day One
1 In the beginning God created the heavens and the earth.
2 and darkness was over the surface of the deep, and the Spirit of God was hovering over the waters.
3 And God said, “Let there be light,” and there was light.
4 God saw that the light was good, and he separated the light from the darkness.
5 God called the light “day,” and the darkness he called “night.” And there was evening, and there was morning—the first day.
Day Two
6 And God said, “Let there be a vault between the waters to separate water from water.”
7 So God made the vault and separated the water under the vault from the water above it. And it was so.
8 God called the vault “sky.” And there was evening, and there was morning—the second day.
Day Three
9 And God said, “Let the water under the sky be gathered to one place, and let dry ground appear.” And it was so.
10 God called the dry ground “land,” and the gathered waters he called “seas.” And God saw that it was good.
Chapter one of Genesis continues to verse 31 then changes to Genesis 2 which has 25 verses etc. for a total of 66 books and 1189 chapters. All the chapters have sporadic sub-headings interspersed within them.Eg. from the above example 'The Beginning-Day One', 'Day Two' and 'Day Three'. Such sub-headings are always short and neither begin nor end with digits.
I made another mistake in my earlier post reply. When I said your code only processed four verses, I meant to write that it processed 4 chapters before it cut out. I have looked at the text where it cut out and can see nothing out of the ordinary. I ran your code twice and it stopped in the same place both times. The total txt file is 4.5 megabytes in size.
I truly appreciate the help you are providing.
Thanks ghostmachine4.
mosquitochalkie
Re: Referencing Bible Verses Individually
Posted: 09 Jan 2011 06:05
by ghostmachine4
so you have provided another set of examples, now i need to see the output that you expect to see from those samples.
Re: Referencing Bible Verses Individually
Posted: 09 Jan 2011 08:51
by mosquitochalkie
Desired output
Genesis 1
The Beginning-Day One
Genesis 1:1 In the beginning God created the heavens and the earth.
Genesis 1:2 and darkness was over the surface of the deep, and the Spirit of God was hovering over the waters.
Genesis 1:3 And God said, “Let there be light,” and there was light.
Genesis 1:4 God saw that the light was good, and he separated the light from the darkness.
Genesis 1:5 God called the light “day,” and the darkness he called “night.” And there was evening, and there was morning—the first day.
Day Two
Genesis 1:6 And God said, “Let there be a vault between the waters to separate water from water.”
Genesis 1:7 So God made the vault and separated the water under the vault from the water above it. And it was so.
Genesis 1:8 God called the vault “sky.” And there was evening, and there was morning—the second day.
Day Three
Genesis 1:9 And God said, “Let the water under the sky be gathered to one place, and let dry ground appear.” And it was so.
Genesis 1:10 God called the dry ground “land,” and the gathered waters he called “seas.” And God saw that it was good.
Thanks again ghostmachine4
mosquitochalkie
Re: Referencing Bible Verses Individually
Posted: 09 Jan 2011 09:45
by mosquitochalkie
Once again I find that I must apologize to both !K and ghostmachine4. It was !K who supplied the batch coding and it is that coding upon which all my subsequent comments have been made. I did not even see the gawk coding supplied by ghostmachine4 until just a few minutes ago. I sincerely apologize to you both for leading you a merry dance. I have not yet tested the gawk coding but will do so now.
Again both my apologies and my grateful thanks to you both.
mosquitochalkie.
Re: Referencing Bible Verses Individually
Posted: 09 Jan 2011 10:08
by mosquitochalkie
To ghostmachine4,
I have now tested your gawk code after downloading and installing gawk and the only output I get is a file named gawk which has no extension and a file size of zero.
The results I previously attributed to you were actually the results of the batch coding supplied by !K.
Sorry I led you up the garden path.
Many thanks anyway.
mosquitochalkie
Re: Referencing Bible Verses Individually
Posted: 09 Jan 2011 10:12
by ghostmachine4
mosquitochalkie wrote:To ghostmachine4,
I have now tested your gawk code after downloading and installing gawk and the only output I get is a file named gawk which has no extension and a file size of zero.
that's definitely not correct. show me how you run the code.
Re: Referencing Bible Verses Individually
Posted: 09 Jan 2011 10:49
by mosquitochalkie
This is the command line I used
C:\bible>gawk "/^[A-Z]/{s=$0;}/^[0-9]/{print s\".\"$0 }" file
where bible.txt is the name of the file I want to change.
mosquitochalkie
Re: Referencing Bible Verses Individually
Posted: 09 Jan 2011 17:52
by ghostmachine4
mosquitochalkie wrote:This is the command line I used
C:\bible>gawk "/^[A-Z]/{s=$0;}/^[0-9]/{print s\".\"$0 }" file
where bible.txt is the name of the file I want to change.
mosquitochalkie
if bible.txt is the name of the file you want to change, then use bible.txt, not "file".