Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Sigil

Notices

Reply
 
Thread Tools Search this Thread
Old 03-02-2023, 06:56 PM   #1
CrispyBacon
Junior Member
CrispyBacon began at the beginning.
 
Posts: 7
Karma: 10
Join Date: Mar 2016
Device: Kindle Fire 7"
Find and deletes lines

Hi Guys,

Is there way to delete an entire line from the entire file.
I'm editing an epub, and I want to delete every line 14 from the entire book.

And is there a way to delete
<p> Chapter 123: Random Chapter Name </p>
<p> Chapter 124: Random Chapter Name </p>
<p> Chapter 125: Random Chapter Name </p>

all in one go. Instead of going to each chapter and deleting that line.

Sorry, I cant think of a better way to explain it
CrispyBacon is offline   Reply With Quote
Old 03-02-2023, 10:35 PM   #2
Turtle91
A Hairy Wizard
Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.
 
Turtle91's Avatar
 
Posts: 3,303
Karma: 20171571
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 15/11/X/6/iPad 1,2,Air & Air Pro/Surface Pro/Kindle PW & Fire
What you are looking for is called a regular expression, or Regex. The basics of Regex-ese is fairly simple and straightforward. Don't get alarmed by some of the more advanced stuff, you (almost) never need the super advanced stuff.

For your Chapter example, I would use:

Find: <p>\s*Chapter (\d+): (.*?)\s*</p>
Replace: [leave blank]

Make sure you have Regex as the Mode and then I would just do them one at a time until you are confident you got them all.

FYI the funny codes are simply wildcards:
Code:
<p>\s*Chapter (\d+): (.*?)\s*</p>

\s* means any (or none) blank spaces
(\d+) means any group of 1, or more, numerical digits
(.*?) means any group of characters before stopping at any space before the </p>
You can find much more in-depth explanation and examples on Regex in the MR Wiki and by doing a search of the threads.

<--->

I'm not aware of a way to select "line 14" and delete it, but if it has a consistent formatting or something that you can use the regex search to find then I'd use that.

Last edited by Turtle91; 03-02-2023 at 10:47 PM.
Turtle91 is offline   Reply With Quote
Advert
Old 03-03-2023, 01:50 AM   #3
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,616
Karma: 29710338
Join Date: Mar 2012
Location: Sydney Australia
Device: none
Quote:
Originally Posted by Turtle91 View Post
<snip>

I'm not aware of a way to select "line 14" and delete it, but if it has a consistent formatting or something that you can use the regex search to find then I'd use that.
If the line 14s don't have any consistently unique content that is regex-able, unzip the epub, then use a script to process the relevant files (e.g. *.html) thru a line editor such as sed or edlin, then zip up the folder and rename as a .epub.

BR
BetterRed is offline   Reply With Quote
Old 03-03-2023, 02:05 AM   #4
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,680
Karma: 23983815
Join Date: Dec 2010
Device: Kindle PW2
Quote:
Originally Posted by Turtle91 View Post
I'm not aware of a way to select "line 14" and delete it, but if it has a consistent formatting or something that you can use the regex search to find then I'd use that.
Can't be done with a regex, but can be easily done with a throwaway plugin.
Spoiler:
Code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys, os

def run(bk):
    for html_id, href in bk.text_iter():
        html = bk.readfile(html_id)
        text = html.splitlines()
        if len(text) > 13:
            value = text[13]
            text.remove(value)
            bk.writefile(html_id, "\r\n".join(text))
            print('{} deleted from {}'.format(value, os.path.basename(href)))

    return 0

def main():
    print('I reached main when I should not have\n')
    return -1

if __name__ == "__main__":
    sys.exit(main())


The line number is hard-coded in the following line:
Code:
            value = text[13]
which obviously needs to be changed for other line numbers. Since Python uses zero-based indexing, the OP'll need to subtract 1 from the line number (text[13] refers to line 14).
Attached Files
File Type: zip DeleteLine.zip (947 Bytes, 82 views)
Doitsu is offline   Reply With Quote
Old 03-03-2023, 08:09 AM   #5
Turtle91
A Hairy Wizard
Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.
 
Turtle91's Avatar
 
Posts: 3,303
Karma: 20171571
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 15/11/X/6/iPad 1,2,Air & Air Pro/Surface Pro/Kindle PW & Fire
Awesome - I'm continually amazed at the level of genius-ery that exists around here!!

I think the next step would be to create a plugin that write's plugin's to order.... anyone want to be a bazillionair???
Turtle91 is offline   Reply With Quote
Advert
Old 04-02-2023, 09:25 AM   #6
CrispyBacon
Junior Member
CrispyBacon began at the beginning.
 
Posts: 7
Karma: 10
Join Date: Mar 2016
Device: Kindle Fire 7"
Thanks Guys!
CrispyBacon is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
EPUB to PDF: hyperlinks that span lines make all of both lines clickable metallserge Conversion 4 09-23-2021 06:39 AM
Glo one book added and one deletes intipuss Kobo Reader 4 03-12-2013 10:02 PM
Touch Dark lines between lines of text taming Kobo Reader 12 06-13-2011 07:20 PM
Save deletes most of the book PKFFW Sigil 3 04-20-2010 02:48 AM
K2 self-deletes 2 books at once BarryTX Amazon Kindle 14 04-09-2010 03:30 PM


All times are GMT -4. The time now is 12:59 AM.


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