Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 02-11-2024, 03:37 PM   #1
zimpt
Junior Member
zimpt began at the beginning.
 
Posts: 4
Karma: 10
Join Date: Feb 2024
Device: Kindle Paperwhite 4th Iteration (Gen. 10)
Use search and replace to add leading zeroes

I want to use search and replace on a bulk of files named "Chapter 1, Chapter 2... Chapter 100" to include leading zeroes so every file is 3 digit long: "Chapter 001, Chapter 002... Chapter100". If I enter "\d+" in the "Search for" field it detects the numbers but I don't know what to put in the "Replace with" field. \\n refers back to the number but how can i modify it conditionally?
zimpt is offline   Reply With Quote
Old 02-11-2024, 04:46 PM   #2
Karellen
Wizard
Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.
 
Karellen's Avatar
 
Posts: 1,103
Karma: 4911876
Join Date: Sep 2021
Location: Australia
Device: Kobo Libra 2
Where exactly are you trying to do this?
Is it in the Editor? Is it the xhtml files or the chapter headings in those files, or is it somewhere else?

I am just not sure where you would see that in "Library Management".
Karellen is online now   Reply With Quote
Old 02-11-2024, 07:14 PM   #3
zimpt
Junior Member
zimpt began at the beginning.
 
Posts: 4
Karma: 10
Join Date: Feb 2024
Device: Kindle Paperwhite 4th Iteration (Gen. 10)
Quote:
Originally Posted by Karellen View Post
Where exactly are you trying to do this?
Is it in the Editor? Is it the xhtml files or the chapter headings in those files, or is it somewhere else?

I am just not sure where you would see that in "Library Management".
In the virtual library selecting them all and clicking "Edit Metadata". Thought it was the right Channel because it has "managing metadata" in its description
zimpt is offline   Reply With Quote
Old 02-11-2024, 07:31 PM   #4
Karellen
Wizard
Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.
 
Karellen's Avatar
 
Posts: 1,103
Karma: 4911876
Join Date: Sep 2021
Location: Australia
Device: Kobo Libra 2
Maybe you can post a screenshot because I am not really understanding where you are seeing "Chapters" in the library listing.
Karellen is online now   Reply With Quote
Old 02-11-2024, 07:33 PM   #5
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: 29,809
Karma: 54830978
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
The place is correct.
What we don't understand is WHY-WHERE this is to be done???
Numeric fields do not show leading 0's (integer>=1). 0.5 will show a single 0

Padding with 0 (or a space) is only valid for Text
You can 'format' filename strings in the send to Disk (or device) template
{series_index:0>5.2f}
That is my template for series_index when included in a filename.
2 digits before the . and 2 after (the 5)
theducks is online now   Reply With Quote
Old 02-11-2024, 07:48 PM   #6
zimpt
Junior Member
zimpt began at the beginning.
 
Posts: 4
Karma: 10
Join Date: Feb 2024
Device: Kindle Paperwhite 4th Iteration (Gen. 10)
Quote:
Originally Posted by Karellen View Post
Maybe you can post a screenshot because I am not really understanding where you are seeing "Chapters" in the library listing.




I want to merge all those epubs. But because sorting by "Title" it sorts digit after digit instead of the whole number I thought it would be the best to add leading zeroes so the chapters are in the right order
(images are not shown for some reason https://imgur.com/a/an1SuqA, https://imgur.com/a/V5tn2Pd)
zimpt is offline   Reply With Quote
Old 02-11-2024, 11:31 PM   #7
BetterRed
null operator (he/him)
BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.
 
Posts: 20,575
Karma: 26954694
Join Date: Mar 2012
Location: Sydney Australia
Device: none
Suggest you look at the EPUBMerge plugin ==>> Index of plugins

BR
BetterRed is offline   Reply With Quote
Old 02-12-2024, 02:57 AM   #8
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 11,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by zimpt View Post
I want to merge all those epubs. But because sorting by "Title" it sorts digit after digit instead of the whole number I thought it would be the best to add leading zeroes so the chapters are in the right order
@BetterRed's suggestion is best, but you can get what you want by checking
the option Preferences / Behavior / Recognize numbers inside text when sorting.
Click image for larger version

Name:	Clipboard07.jpg
Views:	47
Size:	45.5 KB
ID:	206323

With the option unchecked:
Click image for larger version

Name:	Clipboard08.jpg
Views:	48
Size:	11.6 KB
ID:	206322

With the option checked:
Click image for larger version

Name:	Clipboard06.jpg
Views:	48
Size:	12.3 KB
ID:	206324

You can also use a bulk search & replace with source "template" to change the titles to have a fixed number of leading zeros This is complicated and error prone so I don't recommend it. The template would be something like this, assuming that the number always appears at the end and that it can be floating point:
Code:
program:
	text = re($title, '^(.*?)[\d\.]*$', '\1');
	digits = re($title, '.*?((\d+(?:\.\d*)?|\.\d+)).*?', '\1');
	digits = format_number(digits, '08.2f');
	title = text & digits
chaley is offline   Reply With Quote
Old 02-12-2024, 03:38 AM   #9
zimpt
Junior Member
zimpt began at the beginning.
 
Posts: 4
Karma: 10
Join Date: Feb 2024
Device: Kindle Paperwhite 4th Iteration (Gen. 10)
Quote:
Originally Posted by chaley View Post
@BetterRed's suggestion is best, but you can get what you want by checking
the option Preferences / Behavior / Recognize numbers inside text when sorting.
Attachment 206323

With the option unchecked:
Attachment 206322

With the option checked:
Attachment 206324

You can also use a bulk search & replace with source "template" to change the titles to have a fixed number of leading zeros This is complicated and error prone so I don't recommend it. The template would be something like this, assuming that the number always appears at the end and that it can be floating point:
Code:
program:
	text = re($title, '^(.*?)[\d\.]*$', '\1');
	digits = re($title, '.*?((\d+(?:\.\d*)?|\.\d+)).*?', '\1');
	digits = format_number(digits, '08.2f');
	title = text & digits
fixed it thanks
zimpt is offline   Reply With Quote
Reply

Tags
calibre, template language


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Search and replace Th0mC Calibre 2 11-07-2020 07:08 AM
Regex in search problems (NOT Search&Replace; the search bar) lairdb Calibre 3 03-15-2017 07:10 PM
save multiple search/replace, or search/replace multiple ebooks user743 Editor 12 04-12-2014 02:38 AM
How to add leading zeros to the front of a series peaceridge Library Management 4 11-18-2013 11:46 AM
search and replace - drops blanks in replace ? cybmole Conversion 10 03-13-2011 03:07 AM


All times are GMT -4. The time now is 03:57 PM.


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