View Single Post
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,739
Karma: 24031403
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, 89 views)
Doitsu is offline   Reply With Quote