Sign in to follow this  
Followers 0
SirJ

Help reading text from one notepad one line at a time until a blank line is found

7 posts in this topic

I have the King James Bible in plain text format. Each book is a separate text file. An example, Genesis.txt is the file name for the book of Genesis. Each book of the bible if formatted as below:

I want to read each chapter of each book chapter by chapter and write the chapter to a new text file with the chapter number as the new file name. Any help will be appreciated.

Example, the script should read "THE BOOK OF PSALMS" and write it as the first line for all new files created, a blank line printed, read "PSALM 1", write it to the new file on line 3, read the rest of the file until a blank line is met. This will indicate the end of PSALM 1. The new file will them be saved and closed as PSALM 1.TXT.

The script will read the rest of the book until end of file.

THE BOOK OF PSALMS

PSALM 1

1 Blessed [is] the man that walketh not in the counsel of the ungodly, nor standeth in the way of sinners, nor sitteth in the seat of the scornful.

2 But his delight [is] in the law of the LORD; and in his law doth he meditate day and night.

3 And he shall be like a tree planted by the rivers of water, that bringeth forth his fruit in his season; his leaf also shall not wither; and whatsoever he doeth shall prosper.

4 The ungodly [are] not so: but [are] like the chaff which the wind driveth away.

5 Therefore the ungodly shall not stand in the judgment, nor sinners in the congregation of the righteous.

6 For the LORD knoweth the way of the righteous: but the way of the ungodly shall perish.

PSALM 2

1 Why do the heathen rage, and the people imagine a vain thing?

2 The kings of the earth set themselves, and the rulers take counsel together, against the LORD, and against his anointed, [saying],

3 Let us break their bands asunder, and cast away their cords from us.

4 He that sitteth in the heavens shall laugh: the Lord shall have them in derision.

5 Then shall he speak unto them in his wrath, and vex them in his sore displeasure.

6 Yet have I set my king upon my holy hill of Zion.

7 I will declare the decree: the LORD hath said unto me, Thou [art] my Son; this day have I begotten thee.

8 Ask of me, and I shall give [thee] the heathen [for] thine inheritance, and the uttermost parts of the earth [for] thy possession.

9 Thou shalt break them with a rod of iron; thou shalt dash them in pieces like a potter's vessel.

10 Be wise now therefore, O ye kings: be instructed, ye judges of the earth.

11 Serve the LORD with fear, and rejoice with trembling.

12 Kiss the Son, lest he be angry, and ye perish [from] the way, when his wrath is kindled but a little. Blessed [are] all they that put their trust in him.

Share this post


Link to post
Share on other sites



_FileWriteToLine() will allow you to inject lines into your text files.


Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - $7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt

Share this post


Link to post
Share on other sites

_FileWriteToLine() will allow you to inject lines into your text files.

The reason for me doing this is to enable me to put the Bible on my iPOD booting with the RockBox firmware. It will make browsing easier the text on the iPOD easier.

I have no idea how to begin to automate this rather tedious task. I have an idea how the flow should be to read and write each chapter but do not know how to write it. Could you give me a code sample?

Share this post


Link to post
Share on other sites

The reason for me doing this is to enable me to put the Bible on my iPOD booting with the RockBox firmware. It will make browsing easier the text on the iPOD easier.

I have no idea how to begin to automate this rather tedious task. I have an idea how the flow should be to read and write each chapter but do not know how to write it. Could you give me a code sample?

I can whip something up, but I need a bit 'o clarification... Do you want it to take something like this:

1 Blessed [is] the man that walketh not in the counsel of the ungodly, nor standeth in the way of sinners, nor sitteth in the seat of the scornful.
2 But his delight [is] in the law of the LORD; and in his law doth he meditate day and night.
3 And he shall be like a tree planted by the rivers of water, that bringeth forth his fruit in his season; his leaf also shall not wither; and whatsoever he doeth shall prosper.
4 The ungodly [are] not so: but [are] like the chaff which the wind driveth away.
5 Therefore the ungodly shall not stand in the judgment, nor sinners in the congregation of the righteous.
6 For the LORD knoweth the way of the righteous: but the way of the ungodly shall perish.

1 Why do the heathen rage, and the people imagine a vain thing?
2 The kings of the earth set themselves, and the rulers take counsel together, against the LORD, and against his anointed, [saying],
3 Let us break their bands asunder, and cast away their cords from us.
4 He that sitteth in the heavens shall laugh: the Lord shall have them in derision.
5 Then shall he speak unto them in his wrath, and vex them in his sore displeasure.
6 Yet have I set my king upon my holy hill of Zion.
7 I will declare the decree: the LORD hath said unto me, Thou [art] my Son; this day have I begotten thee.
8 Ask of me, and I shall give [thee] the heathen [for] thine inheritance, and the uttermost parts of the earth [for] thy possession.
9 Thou shalt break them with a rod of iron; thou shalt dash them in pieces like a potter's vessel.
10 Be wise now therefore, O ye kings: be instructed, ye judges of the earth.
11 Serve the LORD with fear, and rejoice with trembling.
12 Kiss the Son, lest he be angry, and ye perish [from] the way, when his wrath is kindled but a little. Blessed [are] all they that put their trust in him.

And turn it into this?

PSALM 1.txt:

THE BOOK OF PSALMS

PSALM 1
1 Blessed [is] the man that walketh not in the counsel of the ungodly, nor standeth in the way of sinners, nor sitteth in the seat of the scornful.
2 But his delight [is] in the law of the LORD; and in his law doth he meditate day and night.
3 And he shall be like a tree planted by the rivers of water, that bringeth forth his fruit in his season; his leaf also shall not wither; and whatsoever he doeth shall prosper.
4 The ungodly [are] not so: but [are] like the chaff which the wind driveth away.
5 Therefore the ungodly shall not stand in the judgment, nor sinners in the congregation of the righteous.
6 For the LORD knoweth the way of the righteous: but the way of the ungodly shall perish.

PSALM 2.txt:

THE BOOK OF PSALMS

PSALM 2
1 Why do the heathen rage, and the people imagine a vain thing?
2 The kings of the earth set themselves, and the rulers take counsel together, against the LORD, and against his anointed, [saying],
3 Let us break their bands asunder, and cast away their cords from us.
4 He that sitteth in the heavens shall laugh: the Lord shall have them in derision.
5 Then shall he speak unto them in his wrath, and vex them in his sore displeasure.
6 Yet have I set my king upon my holy hill of Zion.
7 I will declare the decree: the LORD hath said unto me, Thou [art] my Son; this day have I begotten thee.
8 Ask of me, and I shall give [thee] the heathen [for] thine inheritance, and the uttermost parts of the earth [for] thy possession.
9 Thou shalt break them with a rod of iron; thou shalt dash them in pieces like a potter's vessel.
10 Be wise now therefore, O ye kings: be instructed, ye judges of the earth.
11 Serve the LORD with fear, and rejoice with trembling.
12 Kiss the Son, lest he be angry, and ye perish [from] the way, when his wrath is kindled but a little. Blessed [are] all they that put their trust in him.

Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - $7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt

Share this post


Link to post
Share on other sites

I can whip something up, but I need a bit 'o clarification... Do you want it to take something like this:

1 Blessed [is] the man that walketh not in the counsel of the ungodly, nor standeth in the way of sinners, nor sitteth in the seat of the scornful.
2 But his delight [is] in the law of the LORD; and in his law doth he meditate day and night.
3 And he shall be like a tree planted by the rivers of water, that bringeth forth his fruit in his season; his leaf also shall not wither; and whatsoever he doeth shall prosper.
4 The ungodly [are] not so: but [are] like the chaff which the wind driveth away.
5 Therefore the ungodly shall not stand in the judgment, nor sinners in the congregation of the righteous.
6 For the LORD knoweth the way of the righteous: but the way of the ungodly shall perish.

1 Why do the heathen rage, and the people imagine a vain thing?
2 The kings of the earth set themselves, and the rulers take counsel together, against the LORD, and against his anointed, [saying],
3 Let us break their bands asunder, and cast away their cords from us.
4 He that sitteth in the heavens shall laugh: the Lord shall have them in derision.
5 Then shall he speak unto them in his wrath, and vex them in his sore displeasure.
6 Yet have I set my king upon my holy hill of Zion.
7 I will declare the decree: the LORD hath said unto me, Thou [art] my Son; this day have I begotten thee.
8 Ask of me, and I shall give [thee] the heathen [for] thine inheritance, and the uttermost parts of the earth [for] thy possession.
9 Thou shalt break them with a rod of iron; thou shalt dash them in pieces like a potter's vessel.
10 Be wise now therefore, O ye kings: be instructed, ye judges of the earth.
11 Serve the LORD with fear, and rejoice with trembling.
12 Kiss the Son, lest he be angry, and ye perish [from] the way, when his wrath is kindled but a little. Blessed [are] all they that put their trust in him.

And turn it into this?

PSALM 1.txt:

THE BOOK OF PSALMS

PSALM 1
1 Blessed [is] the man that walketh not in the counsel of the ungodly, nor standeth in the way of sinners, nor sitteth in the seat of the scornful.
2 But his delight [is] in the law of the LORD; and in his law doth he meditate day and night.
3 And he shall be like a tree planted by the rivers of water, that bringeth forth his fruit in his season; his leaf also shall not wither; and whatsoever he doeth shall prosper.
4 The ungodly [are] not so: but [are] like the chaff which the wind driveth away.
5 Therefore the ungodly shall not stand in the judgment, nor sinners in the congregation of the righteous.
6 For the LORD knoweth the way of the righteous: but the way of the ungodly shall perish.

PSALM 2.txt:

THE BOOK OF PSALMS

PSALM 2
1 Why do the heathen rage, and the people imagine a vain thing?
2 The kings of the earth set themselves, and the rulers take counsel together, against the LORD, and against his anointed, [saying],
3 Let us break their bands asunder, and cast away their cords from us.
4 He that sitteth in the heavens shall laugh: the Lord shall have them in derision.
5 Then shall he speak unto them in his wrath, and vex them in his sore displeasure.
6 Yet have I set my king upon my holy hill of Zion.
7 I will declare the decree: the LORD hath said unto me, Thou [art] my Son; this day have I begotten thee.
8 Ask of me, and I shall give [thee] the heathen [for] thine inheritance, and the uttermost parts of the earth [for] thy possession.
9 Thou shalt break them with a rod of iron; thou shalt dash them in pieces like a potter's vessel.
10 Be wise now therefore, O ye kings: be instructed, ye judges of the earth.
11 Serve the LORD with fear, and rejoice with trembling.
12 Kiss the Son, lest he be angry, and ye perish [from] the way, when his wrath is kindled but a little. Blessed [are] all they that put their trust in him.

Exactly! This is my desired result, and that the resultant file will be named after the chapter number.

Share this post


Link to post
Share on other sites

Exactly! This is my desired result, and that the resultant file will be named after the chapter number.

There must be an empty line at the top of genesis.txt for this example to work. It's a bit rough, but it gets the job done.

#include <File.au3>

Dim $filecontents
Dim $emptylines[1]
$j = 1

_FileReadToArray("genesis.txt",$filecontents)
For $i = 1 To $filecontents[0]
    If $filecontents[$i] = "" Then ;if the line is blank
        ReDim $emptylines[$j + 1]
        $emptylines[0] = UBound($emptylines) - 1
        $emptylines[$j] = $i
        $j += 1
    EndIf
Next

$psalm = 1
For $i = 1 To $emptylines[0]
    $newfile = FileOpen("PSALM " & $psalm & ".txt",1)
    $psalm += 1
    FileWriteLine($newfile,"THE BOOK OF PSALMS")
    FileWriteLine($newfile,"")
    FileWriteLine($newfile,"PSALM" & $psalm)
    If $i = $emptylines[0] Then
        _FileWriteFromArray($newfile,$filecontents,$emptylines[$i] + 1)
    Else
        _FileWriteFromArray($newfile,$filecontents,$emptylines[$i] + 1,$emptylines[$i + 1] - 1)
    EndIf
    FileClose($newfile)
Next

Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - $7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt

Share this post


Link to post
Share on other sites

There must be an empty line at the top of genesis.txt for this example to work. It's a bit rough, but it gets the job done.

#include <File.au3>

Dim $filecontents
Dim $emptylines[1]
$j = 1

_FileReadToArray("genesis.txt",$filecontents)
For $i = 1 To $filecontents[0]
    If $filecontents[$i] = "" Then ;if the line is blank
        ReDim $emptylines[$j + 1]
        $emptylines[0] = UBound($emptylines) - 1
        $emptylines[$j] = $i
        $j += 1
    EndIf
Next

$psalm = 1
For $i = 1 To $emptylines[0]
    $newfile = FileOpen("PSALM " & $psalm & ".txt",1)
    $psalm += 1
    FileWriteLine($newfile,"THE BOOK OF PSALMS")
    FileWriteLine($newfile,"")
    FileWriteLine($newfile,"PSALM" & $psalm)
    If $i = $emptylines[0] Then
        _FileWriteFromArray($newfile,$filecontents,$emptylines[$i] + 1)
    Else
        _FileWriteFromArray($newfile,$filecontents,$emptylines[$i] + 1,$emptylines[$i + 1] - 1)
    EndIf
    FileClose($newfile)
Next

Thank you! I will put this in Autoit and compile it, make adjustments as necessary, etc. You did the whole work for me. Thanks!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0