Delete Multiple lines in Multiple files
-
Hello.
I’m new to this forum and if this has been answered before then I apologize.
I’m looking to delete about 25 lines in multiple txt-files, and I’m wondering if this is something Notepad++ can do?
I’m a newbie when it comes to RegEx, and may need a bit of walkthrough.
I hope someone can help me.
Thanks in advance.
-
Welcome. Well, you need to be more specific about which 25 lines…what describes them… Only then (and possibly after some back-and-forth about your description of these lines to nail down something that a regex specification can be built from) will anyone be able to help you.
-
The txt in the lines are not the same in any of the files, but here’s an example of what I wanted to delete.
Amphibious Rescue
by Amilyn
Category: Early Edition
Genre: Drama, Humor
Language: English
Status: Completed
Published: 2011-04-25
Updated: 2011-04-25
Packaged: 2015-01-02 07:22:45
Rating: K+
Chapters: 1
Words: 8,041
Publisher: www.fanfiction.net
Story URL: https://www.fanfiction.net/s/6936531/1/
Author URL: https://www.fanfiction.net/u/29600/Amilyn
Summary: The paper wants Gary to save a car wreck victim, stop a gang fight, and prevent a tragedy on a zoo field trip for visually impaired kids. No warnings apply.
I hope this makes sense.
-
There needs to be a discernible pattern to your data that you need to define; we can’t guess because we aren’t in your brain and can’t know what you are getting at.
So a valid thing for you to say might be:
The lines I need to delete always start with a title line, followed by an empty line, followed by a line that starts with “by” and a space and a name, followed by a blank line, then a bunch of lines with other data, and lastly a line that starts with “Summary” , which is the last line of the group to delete.Something like that would be a starting point for offering up some advice on how to solve your problem.
-
I did say I was new, and I didn’t know how to express what I wanted done.
Thank you for the correction.
The lines I need to delete always start with a title line, followed by an empty line, followed by a line that starts with “by” and a space and a name, followed by a blank line, then a bunch of lines with other data, and lastly a line that starts with “Summary” , which is the last line of the group to delete.
Can anyone help me?
-
still not 100% clear to me.
Does this mean that, from your example, you have thisAmphibious Rescue
by Amilyn
Category: Early Edition
Genre: Drama, Humor
Language: English
Status: Completed
Published: 2011-04-25
Updated: 2011-04-25
Packaged: 2015-01-02 07:22:45
Rating: K+
Chapters: 1
Words: 8,041
Publisher: www.fanfiction.net
Story URL: https://www.fanfiction.net/s/6936531/1/
Author URL: https://www.fanfiction.net/u/29600/Amilyn
Summary: The paper wants Gary to save a car wreck victim, stop a gang fight, and prevent a tragedy on a zoo field trip for visually impaired kids. No warnings apply.and want to get that
Category: Early Edition
Genre: Drama, Humor
Language: English
Status: Completed
Published: 2011-04-25
Updated: 2011-04-25
Packaged: 2015-01-02 07:22:45
Rating: K+
Chapters: 1
Words: 8,041
Publisher: www.fanfiction.net
Story URL: https://www.fanfiction.net/s/6936531/1/
Author URL: https://www.fanfiction.net/u/29600/AmilynCould it be that this pattern occurs more often in one file like
Amphibious Rescue
by Amilyn
Category: Early Edition
Genre: Drama, Humor
Language: English
Status: Completed
Published: 2011-04-25
Updated: 2011-04-25
Packaged: 2015-01-02 07:22:45
Rating: K+
Chapters: 1
Words: 8,041
Publisher: www.fanfiction.net
Story URL: https://www.fanfiction.net/s/6936531/1/
Author URL: https://www.fanfiction.net/u/29600/Amilyn
Summary: The paper wants Gary to save a car wreck victim, stop a gang fight, and prevent a tragedy on a zoo field trip for visually impaired kids. No warnings apply.Amphibious Rescue2
by Amilyn2
Category: Early Edition
Genre: Drama, Humor
Language: English
Status: Completed
Published: 2011-04-25
Updated: 2011-04-25
Packaged: 2015-01-02 07:22:45
Rating: K+
Chapters: 1
Words: 8,041
Publisher: www.fanfiction.net
Story URL: https://www.fanfiction.net/s/6936531/1/
Author URL: https://www.fanfiction.net/u/29600/Amilyn
Summary: The paper wants Gary to save a car wreck victim, stop a gang fight, and prevent a tragedy on a zoo field trip for visually impaired kids. No warnings apply.Another title3
by SomeoneElse
Category: Early Edition
Genre: Drama, Humor
Language: English
Status: Completed
Published: 2011-04-25
Updated: 2011-04-25
Packaged: 2015-01-02 07:22:45
Rating: K+
Chapters: 1
Words: 8,041
Publisher: www.fanfiction.net
Story URL: https://www.fanfiction.net/s/6936531/1/
Author URL: https://www.fanfiction.net/u/29600/Amilyn
Summary: and some different summary etc…Cheers
Claudia -
I have 20.000+ txt-files in which I would like to delete everything from the first line to the summary line, and keep the rest of the txt.
-
It appears the OP has undergone an identity crisis…no matter…
OP:
Firstly, I encourage if not demand you make a complete backup copy of your entire original file set…Whew!, now nothing that follows is my fault! :-)
So, this could work, if I have a good understanding of the “spec” on what is needed:
Find what:
(?s).+?\RSummary:[^\r\n]+\R(.+)
Replace with:\1
Search mode:Regular expression
Very high-level summary of what happens with the find and replace:
From the start of file (in a Replace in Files operation) match a string of any characters followed by a line-ending with “Summary:” immediately after; continue matching through (and including) the line-ending of the “Summary:” line. At that point, grab the contents of the remainder of the file and remember it. At replace time, substitute what was remembered (everything after the “Summary:” line) for the contents of the entire file. This effectively deletes the desired lines.For the regex experts out there reading this, I DID try some things with the
\A
anchor (for start-of-file matching), but I recall reading something from @guy038 on a bug with\A
in Notepad++'s regex engine, and my testing bore out that there is a problem with it.