46

I'm able to view an epub file in, say, okular, select all the text and copy-paste into a text editor. I'd like a command line method - anyone know of such a thing?

Braiam
  • 66,947
  • 30
  • 177
  • 264
drevicko
  • 4,303
  • 7
  • 34
  • 42

5 Answers5

54

I don't know if Calibre is worth installing for your job, but if you have it you could use the powerful ebook converter:

ebook-convert input.epub output.txt

Output format is deducted from output file extension

I imagine there could be some XML tools/scripts (XSLT) that can transform epub in text as epub is basically XHTML in ZIP archive

zetah
  • 9,583
  • 10
  • 52
  • 71
  • 1
    Calibre (and it's "ebook-convert") is very powerful tool indeed! Thanks! – drevicko Feb 10 '12 at 07:28
  • 1
    If you've installed calibre on OS X, the command line tool can be found here: `/Applications/calibre.app/Contents/MacOS/ebook-convert`. – funroll Jan 02 '16 at 18:15
  • If you use the command line tool, you might have to configure or set options to get proper output or you could end up with the wrong encoding when converting from epub to plain text for example. Using the app interface, default settings seems to work fine. – lacostenycoder May 01 '17 at 12:01
  • from the documentation, "The options & defaults change, depending on both the input & output formats, so you should always check with: `ebook-convert input.format output.format -h`" (see: https://manual.calibre-ebook.com/generated/en/ebook-convert.html ) – michael Dec 22 '20 at 09:39
10

An alternative is epub2txt by Kevin Boone, available on Github.

epub2html is a simple command-line utility for extracting text from EPUB documents and, optionally, re-flowing it to fit a text display of a particular number of columns. It is written entirely in ANSI-standard C.

Usage example:

epub2txt input.epub > output.txt
Kulfy
  • 17,416
  • 26
  • 64
  • 103
xebeche
  • 341
  • 2
  • 5
  • 1
    from the linked github page (as of 2020): _"Please note that this version of epub2txt is obsolete. It has been completely re-implemented as a new project, epub2txt2"_ https://github.com/kevinboone/epub2txt2 – michael Dec 22 '20 at 09:49
9

MuPDF can convert from epub to html and txt. To install it:

sudo apt install mupdf mupdf-tools

To use it:

mutool convert -o somefilename.txt somefilename.epub 

It assumes txt output from the -o option.

See mutool convert documentation for more information.

xiota
  • 4,709
  • 5
  • 26
  • 53
pierrely
  • 593
  • 4
  • 18
3

Maybe Calibre can suit your needs.

See What formats does calibre support conversion to/from? for information on supported formats.

Eliah Kagan
  • 116,445
  • 54
  • 318
  • 493
Cmorales
  • 1,308
  • 14
  • 25
  • 3
    Whilst this may theoretically answer the question, [it would be preferable](http://meta.stackexchange.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. – hhlp Mar 23 '13 at 10:49
1

To convert an epub document to plain text from terminal:

pandoc input.epub | lynx --stdin --dump > output.txt

It is assumed that pandoc and lynx are already installed.

Name
  • 161
  • 5