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 09-14-2023, 05:24 AM   #1
iamagloworm
Connoisseur
iamagloworm began at the beginning.
 
Posts: 60
Karma: 10
Join Date: Apr 2013
Device: Kindle Paperwhite 3 (Manga)
Possible to use regex to move age-level but not genre to a custom column?

Hello, I have populated my tags column with age-levels like 04-07, 05-10, 16-20 etc. along with genres like fairytale, picture book, animals

I would like to move the age-level to a new column. In the bulk search and replace, I can use a regex like
Code:
(\b\d{2}-\d{2}\b)
to identify the string I want, and in the replace I try something like
Code:
\1
in the new field.

but it copies the genre tags too...

Any advice?

Also, I would prefer to move them, instead of copy, if that is possible.

Thanks!

Last edited by iamagloworm; 09-14-2023 at 04:11 PM.
iamagloworm is offline   Reply With Quote
Old 09-14-2023, 11:50 AM   #2
kjdavies
Zealot
kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.
 
Posts: 112
Karma: 53342
Join Date: Jun 2013
Device: Sony PRS-600
my calibre is tied up right now or I'd actually try this, but... a regex like this might work:

find the books to update:

Code:
tags:"~\b\d\d-\d\d\b"
search field: tags

find:
Code:
^(.*?)((\b\d\d-\d\d\b))+(.*?)$
replace:
Code:
\2,
into:
Code:
#myagetags
The comma will force an empty tag at the end, but that should fall off (empty tags disappear automatically).

This should be nondestructive to the original tags. After your satisfied it works,

search field: tags
find:
Code:
\b\d\d-\d\d\b
replace:

(i.e. replace with nothing)

should strip the age tags. Or you could go into the tag manager and manually select them, then remove from there.

Last edited by kjdavies; 09-14-2023 at 12:04 PM. Reason: improved regex, added 'remove from tags field' part
kjdavies is offline   Reply With Quote
Advert
Old 09-14-2023, 04:06 PM   #3
iamagloworm
Connoisseur
iamagloworm began at the beginning.
 
Posts: 60
Karma: 10
Join Date: Apr 2013
Device: Kindle Paperwhite 3 (Manga)
Thanks for your help. That is how I would expect it to work, but it doesn't. I am wondering if it is something to do with calibre's separator characters
Code:
:::
?
See the attached screenshot if. Am I missing something?
Click image for larger version

Name:	Screenshot 2023-09-14 at 19.08.02.jpg
Views:	74
Size:	371.9 KB
ID:	203765
iamagloworm is offline   Reply With Quote
Old 09-14-2023, 05:42 PM   #4
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,440
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
The problem is that for multiple valued columns like tags, search & replace iterates over the individual values (each tag). It doesn't operate on all of them at once. Thus the regular expression is applied to each tag, not the string of all tags.

You can get around this by using *template as the input field, where the template is something like {tags}. The result of a template is a single value, not multiple values, even if it contains commas. This causes S&R to operate on the single value, not individual ones.

You could even get fancier and have the template generate the value you actually want in the destination column, eliminating the regex. This would be useful mostly if splitting apart the tags requires some logic & conditionals, which doesn't seem to be the case here.
chaley is offline   Reply With Quote
Old 09-15-2023, 06:38 AM   #5
iamagloworm
Connoisseur
iamagloworm began at the beginning.
 
Posts: 60
Karma: 10
Join Date: Apr 2013
Device: Kindle Paperwhite 3 (Manga)
Quote:
Originally Posted by chaley View Post
You can get around this by using *template as the input field, where the template is something like {tags}. The result of a template is a single value, not multiple values, even if it contains commas. This causes S&R to operate on the single value, not individual ones.
This works pretty well, however, if there is no age-level tag is copies the genre tags. Is there a way to prevent this?

My cave-man workaround is just to exclude any books missing age-level tags...

Attached is my config that mostly works:


Click image for larger version

Name:	Screenshot 2023-09-15 at 12.33.21.jpg
Views:	102
Size:	226.2 KB
ID:	203771
iamagloworm is offline   Reply With Quote
Advert
Old 09-15-2023, 07:10 AM   #6
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,440
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by iamagloworm View Post
This works pretty well, however, if there is no age-level tag is copies the genre tags. Is there a way to prevent this?

My cave-man workaround is just to exclude any books missing age-level tags...

Attached is my config that mostly works:


Attachment 203771
To avoid the pre-selection you need to "get fancy".

This works for me. It depends on the tag always being nn-nn with no other leading or trailing characters. It uses the first one it finds. If it desn't find any then it returns ''

The General Program Mode template is
Code:
program:
	for t in $tags:
		if "^\d\d-\d\d$" in t then
			return t
		fi
	rof;
	return ''
The S&R is
Click image for larger version

Name:	Clipboard01.jpg
Views:	70
Size:	156.2 KB
ID:	203772
chaley is offline   Reply With Quote
Old 09-15-2023, 08:14 AM   #7
iamagloworm
Connoisseur
iamagloworm began at the beginning.
 
Posts: 60
Karma: 10
Join Date: Apr 2013
Device: Kindle Paperwhite 3 (Manga)
Awesome, thank you so much!
iamagloworm is offline   Reply With Quote
Old 09-15-2023, 12:36 PM   #8
kjdavies
Zealot
kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.
 
Posts: 112
Karma: 53342
Join Date: Jun 2013
Device: Sony PRS-600
Quote:
Originally Posted by chaley View Post
The problem is that for multiple valued columns like tags, search & replace iterates over the individual values (each tag). It doesn't operate on all of them at once. Thus the regular expression is applied to each tag, not the string of all tags.

You can get around this by using *template as the input field, where the template is something like {tags}. The result of a template is a single value, not multiple values, even if it contains commas. This causes S&R to operate on the single value, not individual ones.

You could even get fancier and have the template generate the value you actually want in the destination column, eliminating the regex. This would be useful mostly if splitting apart the tags requires some logic & conditionals, which doesn't seem to be the case here.
That's what I get for not trying it (calibre was busy doing something).

If examining tags works on a per-tag basis...

Oh. If the tag doesn't match the pattern, it'll still output the original value. You'll copy all the tags.

On the other hand, and this would probably be pretty wasteful, wouldn't this work?

Code:
find: ^(\d\d-\d\d)$
replace: \1
target: #agetag
(concatenate at tags -- ::: inserted)
Then to remove the other tags, I'd probably go to the tag manager, but I suspect the regex replace below could work (probably slowly)

Code:
find: ^(\d\d-\d\d)$
replace:
target: tags (replace with nothing)
If I'm not mistaken -- and I totally could be -- the empty tags should drop out and leave you with just the not-empty tags.

(calibre is busy moving a bunch of files right now, or I'd actually try it and find out)
kjdavies is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
building a genre custom column from tags meghane_e Library Management 3 03-09-2019 09:39 PM
how to move tags data into a new custom column smoothrolla Library Management 6 05-30-2018 07:19 AM
Custom Genre Hierarchical Column to tags jjquin Library Management 5 03-02-2018 12:25 AM
Move selected data from series column to a new custom column fvdham Library Management 3 06-02-2017 03:49 PM
how to move value(s) of tag column to a custom made column zoorakhan Library Management 0 12-08-2012 03:53 AM


All times are GMT -4. The time now is 06:32 PM.


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