Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Sigil

Notices

Reply
 
Thread Tools Search this Thread
Old 09-26-2014, 01:41 AM   #1
Keeth
Junior Member
Keeth began at the beginning.
 
Posts: 5
Karma: 10
Join Date: Sep 2014
Device: iPad 3
Question Mass find and replace for chapter numbers

Hi,
I have an ebook that I am trying to tidy up. It was all one single text file and only had an asterisk to show where chapters ended. I managed to use find and replace to split the text into chapters and put each of those chapters into its own file. However, at the moment the chapter headings just read "Chapter". I would like to have the chapter numbers in the chapter headings but there are nearly 200 hundred chapters so I don't want to do it manually. Is there a way that I can get Sigil to automatically insert the chapter numbers? I was thinking there might be a way to do it with regex? Maybe something like:
Find: Chapter
Replace: Chapter ????
Where ???? inserts a number starting at one and increments every time it is inserted...

Any ideas?

(Sigil 0.7.4 on Mac 10.9.4)
Keeth is offline   Reply With Quote
Old 09-26-2014, 02:03 AM   #2
cybmole
Wizard
cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.
 
Posts: 3,720
Karma: 1759970
Join Date: Sep 2010
Device: none
i did something similar one time. I used regex to "find" the number bit of the ID tag which was in each file, and which already incremented, then "replaced" that into the chapter heading location. so you have any such tags to work from ?
cybmole is offline   Reply With Quote
Advert
Old 09-26-2014, 03:25 AM   #3
Keeth
Junior Member
Keeth began at the beginning.
 
Posts: 5
Karma: 10
Join Date: Sep 2014
Device: iPad 3
Where would I find these ID tags?
Keeth is offline   Reply With Quote
Old 09-26-2014, 04:20 AM   #4
jbacelar
Interested in the matter
jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.
 
jbacelar's Avatar
 
Posts: 421
Karma: 426094
Join Date: Dec 2011
Location: Spain, south coast
Device: Pocketbook InkPad 3
First, sorry for my horrible English.

What I do to renumber notes.
Required:
The text in question in a single file. In your case put behind each "Chapter" a character that does not exist in the original file. For example @.
Phyton 2.7 installed.
Run the py, which attached, in the folder where the file is.
And that's it!

Note:
Change the extension "Renumerar notas.txt" a "Renumerar notas.py".
Of course, first you have to tune the py your needs. (With any text editor).
n = start counter. (Usually 0)
i = increased. (Usually 1)
regex = search the strange character. In this case: re.compile (r "(@)")
files = ["file name"]
The file extension (shown as html), you put the need.

I hope you find it useful.
Attached Files
File Type: txt Renumerar notas.txt (377 Bytes, 323 views)
jbacelar is offline   Reply With Quote
Old 09-26-2014, 04:35 AM   #5
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,584
Karma: 22735033
Join Date: Dec 2010
Device: Kindle PW2
Quote:
Originally Posted by cybmole View Post
i did something similar one time. I used regex to "find" the number bit of the ID tag which was in each file, and which already incremented, then "replaced" that into the chapter heading location. so you have any such tags to work from ?
Unfortunately, Sigil only adds ids to heading tags, if there are multiple heading tags in a file.

@Keeth: You'll have to outsmart Sigil and make it add sequential ids to each heading tag. Assuming that each chapter is a separate .html file and contains only one heading tag at the beginning of the file, for example <h3>Chapter</h3> do the following:

1. Replace all <h3>Chapter</h3> with <h3>Chapter</h3><h4>Chapter</h4>.

2. Regenerate the TOC. You should end up with: <h3>Chapter</h3><h4 id="sigil_toc_id_1">Chapter</h4> for the first chapter.

3. Replace all <h3>Chapter</h3> with nothing. I.e. delete them.

4. Now you can finally add the chapter numbers. Change the mode to Regex and use the following expressions:

Find:<h4 id="sigil_toc_id_(\d+)">(.*?)</h4>
Replace:<h3 id="sigil_toc_id_\1">\2 \1</h3>

5. Regenerate the TOC.
Doitsu is offline   Reply With Quote
Advert
Old 09-26-2014, 05:57 AM   #6
Keeth
Junior Member
Keeth began at the beginning.
 
Posts: 5
Karma: 10
Join Date: Sep 2014
Device: iPad 3
Quote:
Originally Posted by Doitsu View Post
Find:<h4 id="sigil_toc_id_(\d+)">(.*?)</h4>
Replace:<h3 id="sigil_toc_id_\1">\2 \1</h3>
That looks very interesting. Would you mind explaining what each bit is actually doing? I am not familiar with the regex codes...

Thanks
Keeth is offline   Reply With Quote
Old 09-26-2014, 06:31 AM   #7
cybmole
Wizard
cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.
 
Posts: 3,720
Karma: 1759970
Join Date: Sep 2010
Device: none
Quote:
Originally Posted by Keeth View Post
Where would I find these ID tags?
I am guessing here, but i think if you tell sigil to build a TOC, it creates them for you and adds them to code view- or maybe it's calibre that creates them when you do an epub to epub conversion - you'd have to experiment but it should still be a lot quicker than typing in 200 of them manually.

update: I see a more comprehensive answer has already been provided - I suggest you just follow that.
cybmole is offline   Reply With Quote
Old 09-26-2014, 07:22 AM   #8
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,584
Karma: 22735033
Join Date: Dec 2010
Device: Kindle PW2
Quote:
Originally Posted by Keeth View Post
Quote:
Originally Posted by Doitsu View Post
Find:<h4 id="sigil_toc_id_(\d+)">(.*?)</h4>
Replace:<h3 id="sigil_toc_id_\1">\2 \1</h3>
That looks very interesting. Would you mind explaining what each bit is actually doing? I am not familiar with the regex codes...
I's a fairly simple expression and I'm pretty sure that the Regex gurus who read the posts in this forum will come up with a much more efficient one.

The search expression (\d+) searches for one or more numbers. (Putting it in brackets allows it to recycle the match as \1 in the replace statement.)
The search expression (.*?) searches for any sequence of characters. Since it's the second bracketed expression, whatever matches it, can be referred to as \2 in the replace statement.

There are lots of Regex tutorials that explain all of this in much more detail, and there's also a Sigil Regex subforum.
Doitsu is offline   Reply With Quote
Old 09-26-2014, 05:50 PM   #9
pete6055
Connoisseur
pete6055 began at the beginning.
 
Posts: 66
Karma: 10
Join Date: Nov 2012
Device: none
A Suggestion

All of this goes back to a fix for issue 1961 made in November 2012 (see https://www.mobileread.com/forums/sho...d.php?t=206193)
Now that Sigil is back in development, maybe the contemplated enhancements can be picked up again?

Or at least make the appearance of the sigil_toc_id configurable in preferences so as to mimic the pre-issue-1961-fix behavior, so as to avoid merging all files into one.
pete6055 is offline   Reply With Quote
Old 09-27-2014, 10:20 AM   #10
Keeth
Junior Member
Keeth began at the beginning.
 
Posts: 5
Karma: 10
Join Date: Sep 2014
Device: iPad 3
@Doitsu your solution has worked perfectly! Thank you

Is there a similar thing I could do do rename the actual file names? I have a couple of hundred files named "index_split_000_001.xhtml" etc. Is there a way I can get them named "Chapter_1.xhtml" etc.?
Keeth is offline   Reply With Quote
Old 09-27-2014, 10:48 AM   #11
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,584
Karma: 22735033
Join Date: Dec 2010
Device: Kindle PW2
Quote:
Originally Posted by Keeth View Post
Is there a similar thing I could do do rename the actual file names? I have a couple of hundred files named "index_split_000_001.xhtml" etc. Is there a way I can get them named "Chapter_1.xhtml" etc.?
That feature is actually built into the software. Simply select all files in the book browser, right-click the files, select Rename, enter chapter1 and press Enter. Sigil will then automatically increment all remaining file names.
Doitsu is offline   Reply With Quote
Old 09-27-2014, 08:37 PM   #12
Keeth
Junior Member
Keeth began at the beginning.
 
Posts: 5
Karma: 10
Join Date: Sep 2014
Device: iPad 3
Great! Thank you so much for the help
Keeth is offline   Reply With Quote
Old 09-28-2014, 05:10 PM   #13
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
Quote:
Originally Posted by jbacelar View Post
First, sorry for my horrible English.

What I do to renumber notes.
Required:
The text in question in a single file. In your case put behind each "Chapter" a character that does not exist in the original file. For example @.
Phyton 2.7 installed.
Run the py, which attached, in the folder where the file is.
And that's it!

Note:
Change the extension "Renumerar notas.txt" a "Renumerar notas.py".
Of course, first you have to tune the py your needs. (With any text editor).
n = start counter. (Usually 0)
i = increased. (Usually 1)
regex = search the strange character. In this case: re.compile (r "(@)")
files = ["file name"]
The file extension (shown as html), you put the need.

I hope you find it useful.
Perhaps you'd like to turn that into a Sigil plugin?
eschwartz is offline   Reply With Quote
Old 09-28-2014, 06:32 PM   #14
jbacelar
Interested in the matter
jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.
 
jbacelar's Avatar
 
Posts: 421
Karma: 426094
Join Date: Dec 2011
Location: Spain, south coast
Device: Pocketbook InkPad 3
Quote:
Originally Posted by eschwartz View Post
Perhaps you'd like to turn that into a Sigil plugin?
Sounds like a great idea.
But will have to be someone else, because I have no knowledge to do so.
Can you be yourself?
jbacelar is offline   Reply With Quote
Reply

Tags
chapter, number, regex, sigil


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Sigil find and replace page numbers montalex Sigil 8 03-28-2017 08:51 PM
Mass Find and Replace portersprings Sigil 5 08-20-2014 05:57 PM
Find/Replace Won't Find Rand Brittain Sigil 7 09-24-2011 04:35 AM
Find, replace, split chapter? laelaps Sigil 8 01-20-2011 04:01 PM
fixing up chapter numbers cybmole Sigil 4 01-12-2011 02:49 AM


All times are GMT -4. The time now is 12:31 PM.


MobileRead.com is a privately owned, operated and funded community.