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 03-07-2021, 08:47 PM   #1
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 10,876
Karma: 74203799
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Help with a search&replace

I wanted to make some search & replaces for an Action Chain to populate one column based on values from another, like these (note the latter should also be 'prepend to field,' I forgot to set it before screenshotting it):

Click image for larger version

Name:	2021-03-07 21_44_01-Editing metadata for one book.png
Views:	148
Size:	45.9 KB
ID:	185808

Click image for larger version

Name:	2021-03-07 21_46_09-Editing metadata for one book.png
Views:	150
Size:	44.3 KB
ID:	185809

As the results show, it also copies all values from Genre (tag-like composite) instead of just the one i want. What should I do?


Last edited by ownedbycats; 03-07-2021 at 10:07 PM.
ownedbycats is offline   Reply With Quote
Old 03-08-2021, 02:47 AM   #2
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: 21,689
Karma: 29711016
Join Date: Mar 2012
Location: Sydney Australia
Device: none
Quote:
Originally Posted by ownedbycats View Post
What should I do?
Less calibrating and more gardening

BR
BetterRed is offline   Reply With Quote
Advert
Old 03-08-2021, 04:49 AM   #3
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: 12,400
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Search and replace operates on the individual values, not the set of them, changing only the text that matches. Any values that are not matched are not changed. Said another way, S&R does:
Code:
for each item in the list:
    find text in item that matches the search expression
    replace that text with the replacement expression
return the list with replacements
This is what you are seeing.

It seems that what you want is:
Code:
for each book:
    if #genre contains text then add new_text to #kobocoll
As you are using action chains I would do this with a template in a single-field-edit action setting #kobocoll. The template would be something like this:
Code:
program:
	g = field('#genre');
	k = field('#kobocoll');
	if list_contains(g, ',', '^Cozy Mystery$', '1', '') then
		k = list_union(k, 'Cozy Mysteries', ',')
	fi;
	if list_contains(g, ',', '^(Fantasy|Science Fiction)$', '1', '') then
		k = list_union(k, 'Fantasy & Sci-Fi', ',')
	fi;
	k
You can do it with two search/replace's. One would be something like this:
  • source "Template"
  • template
    Code:
    {#genre:'list_contains($, ',', '^Cozy Mystery$', 'Cozy Mysteries', '')'}
  • Search for: '(.*)'
  • Replace with '\1'
The other would be similar, with the other text values

Last edited by chaley; 03-08-2021 at 08:47 AM.
chaley is offline   Reply With Quote
Old 03-08-2021, 04:53 PM   #4
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 10,876
Karma: 74203799
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
I'll try that. Hopefully it won't overwrite other existing entries.

EDIT: I used the template. It worked and did not remove existing entries.

Last edited by ownedbycats; 03-08-2021 at 07:05 PM.
ownedbycats is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Search & Replace changes in 3.0 Phssthpok Editor 4 06-21-2017 04:04 AM
Regex in search problems (NOT Search&Replace; the search bar) lairdb Calibre 3 03-15-2017 07:10 PM
Search & Replace Help paulfiera Conversion 7 08-06-2015 03:52 AM
Help with a search & replace mmholt Library Management 11 10-21-2011 06:49 PM
Search & Replace Pat Nickholds Sigil 2 10-21-2010 11:18 PM


All times are GMT -4. The time now is 09:03 AM.


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