Remove last 5 characters from lines in text file?
-
Hi everyone,
I would like to get Notepad++ to remove the last 5 lines from a text file I have. I want to turn this
10 Cloverfield Lane 2016
12 Angry Men 1957into this
10 Cloverfield Lane
12 Angry MenI have Googled but I’m stuck. Thanks for any help.
-
@drghty said in Remove last 5 characters from lines in text file?:
Hi everyone,
I would like to get Notepad++ to remove the last 5 lines from a text file I have.Make sure caret is at start of file, or at or before first line you want to be affected, or enable
Wrap around
Search Mode =Regular expressionFIND:
.{5}$
REPLACE: [empty].{5}matches any five characters
$matches the end of the line -
@M-Andre-Z-Eckenrode
Slightly off, because you need to make sure that.doesn’t match newline.
Correct find/replace is
FIND:(?-s).{5}$((?-s)turns OFF. matches newline)
REPLACE: [empty] -
By the way, you wrote “remove the last 5 lines from a text file”, but your example indicates removal of the last 5 characters from each line, so I assume the latter was correct.
Ah, yes — my bad, and thanks much for the correction.
For @drghty , just to make sure you understand why Mark’s correction is potentially important, depending on the total content of your text file, my FIND pattern
.{5}$would also match up to five consecutive newline sequences, if your file has multiple consecutive newlines, if it does not include(?-s), or you don’t have. matches newlinedisabled.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login