Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Sigil

Notices

Reply
 
Thread Tools Search this Thread
Old 02-27-2020, 07:09 AM   #1
beiti
Member
beiti is on a distinguished road
 
Posts: 18
Karma: 50
Join Date: Oct 2015
Device: several
Scripted "Find & Replace"?

Sometimes I need to do a long list of "Find & Replace" actions (changing formatting for various image sizes, deleting unwanted formatting in css files etc.). These actions always stay the same (at least for a specific sort of EPUBs I usually have to deal with).
At the moment I use a text file as a "cheat sheet" so that I can work through the list step by step (and be able to use Copy & Paste). Thats okay, but It always takes some extra time.
Is there a way to automate this, so that a list of replace actions can be done by itself?
beiti is offline   Reply With Quote
Old 02-27-2020, 07:25 AM   #2
doubleshuffle
Unicycle Daredevil
doubleshuffle ought to be getting tired of karma fortunes by now.doubleshuffle ought to be getting tired of karma fortunes by now.doubleshuffle ought to be getting tired of karma fortunes by now.doubleshuffle ought to be getting tired of karma fortunes by now.doubleshuffle ought to be getting tired of karma fortunes by now.doubleshuffle ought to be getting tired of karma fortunes by now.doubleshuffle ought to be getting tired of karma fortunes by now.doubleshuffle ought to be getting tired of karma fortunes by now.doubleshuffle ought to be getting tired of karma fortunes by now.doubleshuffle ought to be getting tired of karma fortunes by now.doubleshuffle ought to be getting tired of karma fortunes by now.
 
doubleshuffle's Avatar
 
Posts: 13,944
Karma: 185432100
Join Date: Jan 2011
Location: Planet of the Pudding Brains
Device: Aura HD (R.I.P. After six years the USB socket died.) tolino shine 3
No idea about automating a sequence of Find&Replace actions, but it will certainly save you some time if you use the Saved Searches function of Sigil. (Ctrl+Alt+F, or in the Tools menu). You can save all the entries from your cheat sheet there and just load them from there.
doubleshuffle is offline   Reply With Quote
Old 02-27-2020, 07:45 AM   #3
beiti
Member
beiti is on a distinguished road
 
Posts: 18
Karma: 50
Join Date: Oct 2015
Device: several
Quote:
Originally Posted by doubleshuffle View Post
it will certainly save you some time if you use the Saved Searches function of Sigil.
Thanks for the hint. 'Saved Searches' is a part of Sigil I may have underestimated and therefore not used until now. It's not really what I was looking for but could be a step forward.
beiti is offline   Reply With Quote
Old 02-27-2020, 07:52 AM   #4
doubleshuffle
Unicycle Daredevil
doubleshuffle ought to be getting tired of karma fortunes by now.doubleshuffle ought to be getting tired of karma fortunes by now.doubleshuffle ought to be getting tired of karma fortunes by now.doubleshuffle ought to be getting tired of karma fortunes by now.doubleshuffle ought to be getting tired of karma fortunes by now.doubleshuffle ought to be getting tired of karma fortunes by now.doubleshuffle ought to be getting tired of karma fortunes by now.doubleshuffle ought to be getting tired of karma fortunes by now.doubleshuffle ought to be getting tired of karma fortunes by now.doubleshuffle ought to be getting tired of karma fortunes by now.doubleshuffle ought to be getting tired of karma fortunes by now.
 
doubleshuffle's Avatar
 
Posts: 13,944
Karma: 185432100
Join Date: Jan 2011
Location: Planet of the Pudding Brains
Device: Aura HD (R.I.P. After six years the USB socket died.) tolino shine 3
Perhaps when the experts chime in, someone will be able to come up with some kind of script. That's beyond my capabilities. But Saved Searches will at least save you the trouble of doing Copy&Paste each time.
doubleshuffle is offline   Reply With Quote
Old 02-27-2020, 07:53 AM   #5
najgori
Klak
najgori gives new meaning to the word 'superlative.'najgori gives new meaning to the word 'superlative.'najgori gives new meaning to the word 'superlative.'najgori gives new meaning to the word 'superlative.'najgori gives new meaning to the word 'superlative.'najgori gives new meaning to the word 'superlative.'najgori gives new meaning to the word 'superlative.'najgori gives new meaning to the word 'superlative.'najgori gives new meaning to the word 'superlative.'najgori gives new meaning to the word 'superlative.'najgori gives new meaning to the word 'superlative.'
 
najgori's Avatar
 
Posts: 174
Karma: 150374
Join Date: Sep 2011
Location: Belgrade, Serbia
Device: many
I do it in Notepad++ with Pythonscript plugin
In one window is modified Python Regex Replacement script in another xhmtl file I work on.
In script window you edit and save regex.
In xhtml file window you run script from first window.
Also very useful is Notepad++ Compare plugin because... regex.
najgori is offline   Reply With Quote
Old 02-27-2020, 07:59 AM   #6
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 30,989
Karma: 60358908
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
Quote:
Originally Posted by beiti View Post
Thanks for the hint. 'Saved Searches' is a part of Sigil I may have underestimated and therefore not used until now. It's not really what I was looking for but could be a step forward.
Create a GROUP (of) saved searches: move (drag) all those individual, saved into the group. Execute The Group. It sequences thru the group

1)Saved search does NOT save the S&R mode or scope , so you need a separate groups for CSS, REGEX and Normal mode. Watch out for the Scope Gotcha if your S&R has needed restrictions.
theducks is offline   Reply With Quote
Old 02-27-2020, 08:26 AM   #7
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 28,524
Karma: 204127028
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
As theducks has mentioned, you can create a group of saved searches. Then when you highlight/load the group in the Saved Searches dialog (make sure Find & Replace widget is open), the Find/Replace operations of the Saved Searches dialog will sequentially go through each individual F&R expression in the group.
DiapDealer is offline   Reply With Quote
Old 02-27-2020, 09:52 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,719
Karma: 24031401
Join Date: Dec 2010
Device: Kindle PW2
Quote:
Originally Posted by beiti View Post
Is there a way to automate this, so that a list of replace actions can be done by itself?
If you're familiar with scripting languages, you might be able to create an ad-hoc plugin. See this post for a very simple example.
Doitsu is offline   Reply With Quote
Old 02-27-2020, 09:56 AM   #9
beiti
Member
beiti is on a distinguished road
 
Posts: 18
Karma: 50
Join Date: Oct 2015
Device: several
Thank you, theducks and DiapDealer, for explaining the group option! I just did some quick tests and will try it out in detail very soon. That is actually close to what I was looking for (except for the need to do it separately for CSS and HTML files and keep an eye on the scope setting; I think I can live with that).

Quote:
Originally Posted by najgori
I do it in Notepad++ with Pythonscript plugin
Your method would be editing single xhtml files outside of Sigil? And I had to learn some Pythonscript first?

Quote:
Originally Posted by Doitsu
If you're familiar with scripting languages
To be honest, I was trying to avoid this.
beiti is offline   Reply With Quote
Old 02-27-2020, 10:56 AM   #10
najgori
Klak
najgori gives new meaning to the word 'superlative.'najgori gives new meaning to the word 'superlative.'najgori gives new meaning to the word 'superlative.'najgori gives new meaning to the word 'superlative.'najgori gives new meaning to the word 'superlative.'najgori gives new meaning to the word 'superlative.'najgori gives new meaning to the word 'superlative.'najgori gives new meaning to the word 'superlative.'najgori gives new meaning to the word 'superlative.'najgori gives new meaning to the word 'superlative.'najgori gives new meaning to the word 'superlative.'
 
najgori's Avatar
 
Posts: 174
Karma: 150374
Join Date: Sep 2011
Location: Belgrade, Serbia
Device: many
Quote:
Originally Posted by beiti View Post
Your method would be editing single xhtml files outside of Sigil? And I had to learn some Pythonscript first?
No python script - just vanilla regex, and this script is part od plugin samples. It's trivial for anyone with basic knowledge of regex.
My "method" was to FIRST "regex" indesign exported single xhtml epub and THAN to split it to chapters.
najgori is offline   Reply With Quote
Old 02-27-2020, 08:36 PM   #11
Tex2002ans
Wizard
Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.
 
Posts: 2,306
Karma: 13057279
Join Date: Jul 2012
Device: Kobo Forma, Nook
Just to explain Groups/Saved Searches with pictures:

Click image for larger version

Name:	Sigil.Saved.Searches.Tutorial.png
Views:	197
Size:	41.9 KB
ID:	177405

1. Press Ctrl+F to open Find/Replace.

Change the Mode + All HTML Files to what you want use. In this case, I have "Regex" + "All HTML Files".

2. Press Tools > Saved Searches.

In the Saved Searches window, you're able to create Groups of searches (groups appear Bold).

Create your entire set of Find/Replaces.

3. When you're ready to run the entire batch of Find/Replaces at once:

Highlight the group you want to run (#2 in the image).

Then press Replace All (#3 in the image).
Tex2002ans is offline   Reply With Quote
Old 02-27-2020, 09:23 PM   #12
hobnail
Running with scissors
hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.
 
Posts: 1,584
Karma: 14328510
Join Date: Nov 2019
Device: none
Quote:
Originally Posted by Tex2002ans View Post
Just to explain Groups/Saved Searches with pictures:

Could you attach your .ini file here? I could make use of stuff in it.
hobnail is offline   Reply With Quote
Old 02-28-2020, 03:23 AM   #13
Tex2002ans
Wizard
Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.
 
Posts: 2,306
Karma: 13057279
Join Date: Jul 2012
Device: Kobo Forma, Nook
Quote:
Originally Posted by hobnail View Post
Could you attach your .ini file here? I could make use of stuff in it.
No. But feel free to look through my old posts. I've posted a ton of the Regex I use over the years, like this post from 2019.

Any in particular you're looking for?

Last edited by Tex2002ans; 02-28-2020 at 03:25 AM.
Tex2002ans is offline   Reply With Quote
Old 02-28-2020, 03:30 AM   #14
beiti
Member
beiti is on a distinguished road
 
Posts: 18
Karma: 50
Join Date: Oct 2015
Device: several
Yesterday I spent the evening putting the entries from my cheat sheet into the saved searches mask. I even added a few more details and tested it thoroughly.
It now works great and will save me a lot of time in the future!
I still need a checklist to edit my EPUBs because I need to do three separate runs of 'saved searches' for different kinds of files and with different Regex/Normal and AllFiles/CurrentFile settings. There are also some more things to do that can't be part of find&replace operations (like adding an HTML TOC, adding a cover, editing metadata). But these things are quickly done (unlike a long list of manual replace operations).
So I'm very happy with what I learned in this thread.
Attached Thumbnails
Click image for larger version

Name:	beiti_saved_searches.png
Views:	188
Size:	94.6 KB
ID:	177417  
beiti is offline   Reply With Quote
Old 02-28-2020, 05:54 PM   #15
Tex2002ans
Wizard
Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.
 
Posts: 2,306
Karma: 13057279
Join Date: Jul 2012
Device: Kobo Forma, Nook
Quote:
Originally Posted by beiti View Post
Yesterday I spent the evening putting the entries from my cheat sheet into the saved searches mask. I even added a few more details and tested it thoroughly.

[...]

So I'm very happy with what I learned in this thread.


There's also the Sigil Manual (User Guide).

There's lots of other helpful functionality you'll run across to make your life easier.
Tex2002ans is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Default "find" for Search/Replace regex functions vr8ce Editor 14 02-02-2018 10:41 AM
Missing "function mode" for editor's Search & Replace atux Editor 3 01-17-2016 08:40 AM
Find / Replace does not respect "down" setting DrChiper Editor 24 01-26-2014 06:10 PM
MS Word Find & Replace and "Smart" quotes question. Ahu Lee Workshop 1 01-14-2013 11:02 AM
timefmt, align="center", find replace Kirk Vomit Recipes 0 04-11-2012 05:03 AM


All times are GMT -4. The time now is 06:48 AM.


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