Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Conversion

Notices

Reply
 
Thread Tools Search this Thread
Old 04-11-2018, 12:27 PM   #1
Shagbark
Member
Shagbark began at the beginning.
 
Posts: 13
Karma: 10
Join Date: Jul 2015
Device: Nook Simpletouch
How to make ebook-convert use multi-line mode regexp?

I want to use ^ and $ in regular expressions in ebook-convert, but it apparently doesn't operate in multi-line mode.

$ cat > sample.txt
abc def ghi
<ctrl-d>

$ ebook-convert.exe sample.txt sample2.txt --sr1-search "abc" --sr1-replace 'zzz'
Conversion options changed from defaults:
sr1_replace: u'zzz'
sr1_search: u'abc'
1% Converting input to HTML...
InputFormatPlugin: TXT Input running
on Z:\data\text\sci\physics\thermodynamics\sample.txt
Language not specified
Creator not specified
Building file list...
Normalizing filename cases
Rewriting HTML links
flow is too short, not running heuristics
Forcing index.html into XHTML namespace
34% Running transforms on e-book...
Merging user specified metadata...
Detecting structure...
Auto generated TOC with 0 entries.
Flattening CSS and remapping font sizes...
Source base font size is 12.00000pt
Removing fake margins...
Cleaning up manifest...
Trimming unused files from manifest...
Creating TXT Output...
67% Running TXT Output plugin
Converting XHTML to TXT...
TXT output written to Z:\scratch\sample2.txt
Output saved to Z:\scratch\sample2.txt

$ cat sample2.txt
zzz def ghi

$ ebook-convert.exe sample.txt sample2.txt --sr1-search "^abc" --sr1-replace 'zzz'
Conversion options changed from defaults:
sr1_replace: u'zzz'
sr1_search: u'^abc'
1% Converting input to HTML...
InputFormatPlugin: TXT Input running
on Z:\data\text\sci\physics\thermodynamics\sample.txt
Language not specified
Creator not specified
Building file list...
Normalizing filename cases
Rewriting HTML links
flow is too short, not running heuristics
Forcing index.html into XHTML namespace
34% Running transforms on e-book...
Merging user specified metadata...
Detecting structure...
Auto generated TOC with 0 entries.
Flattening CSS and remapping font sizes...
Source base font size is 12.00000pt
Removing fake margins...
Cleaning up manifest...
Trimming unused files from manifest...
Creating TXT Output...
67% Running TXT Output plugin
Converting XHTML to TXT...
TXT output written to Z:\scratch\sample2.txt
Output saved to Z:\scratch\sample2.txt

$ cat sample2.txt
abc def ghi

Same result if I use --sr1-search "^abc" instead of --sr1-search '^abc'.
Shagbark is offline   Reply With Quote
Old 04-11-2018, 12:37 PM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Prefix with (?m)
kovidgoyal is offline   Reply With Quote
Old 04-11-2018, 03:29 PM   #3
Shagbark
Member
Shagbark began at the beginning.
 
Posts: 13
Karma: 10
Join Date: Jul 2015
Device: Nook Simpletouch
Where does the ?m go?

$ ebook-convert.exe sample.txt sample2.txt --sr1-search '?m^abc' --sr1-replace 'zzz'
...
$ cat sample2.txt
=~ abc def

(It actually puts the =~ into the output, which makes me suspect the program is somehow dropping a bit of its own pattern-matching source code into the output. This is win64 version 3.21 on Windows 7; I just updated it this morning.)

I figured out how to do what I need to do without multi-line mode, so I don't need an answer right now. But this =~ might be a bug.

Last edited by Shagbark; 04-11-2018 at 03:33 PM.
Shagbark is offline   Reply With Quote
Old 04-11-2018, 10:29 PM   #4
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
You are missing the parentheses and this is all documented in the manual https://manual.calibre-ebook.com/reg...reference.html
kovidgoyal is offline   Reply With Quote
Reply

Tags
ebook-convert, regexp


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Change ebook metadata using filename in command-line mode hfpop Calibre 4 02-18-2016 05:35 PM
Multiple line title with ebook-convert Dyspeptica Conversion 3 08-20-2012 09:24 PM
ebook-convert: change settings from command line miwie Calibre 1 11-30-2010 02:05 PM
Multiple line regexp janvanmaar Calibre 19 11-02-2010 01:02 PM
Command Line Options for ebook-convert godel10 Calibre 14 08-08-2009 08:28 AM


All times are GMT -4. The time now is 01:49 AM.


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