Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select (remove) every 6th (Nth) line in a text file?

Tags:

notepad++

I need to reformat a log file of similar format and have been using Notepad++ macros.

Example:

[00:55:48] Profile Information:

[00:55:48] Name: Joe Bloggs

[00:55:48] Age: 21

[00:55:48] Profile Information:

[00:55:48] Name: Joe Bloggs 2

[00:55:48] Age: 22

I need the format to be:

Joe Bloggs
21
Joe Bloggs 2
22

I can do this with the following operations in a macro but that only gets me so far.

Remove timestamps [[^[]]*]

Remove empty lines Edit > Line Operations > Remove Empty Lines

Replace following with nothing Name: Age:

Then I would need to select every say, 2nd line and remove everything else so I am left with a list of every second line - something like:

21
22

Hoping someone more familiar with Regex and such can chime in with pointers and advice.

like image 310
D. Joe Avatar asked Oct 26 '25 10:10

D. Joe


1 Answers

I am not sure of what you are asking for. You title is about selecting every 7th line in a textfile but your sample is not related to that.

Anyway, I am guessing that you want to select every 7th line in a text file with notepad++.

You can do something like this:

  1. Remove the empty lines: Edit > Line Operations > Remove Empty Lines

  2. With Search & Replace(on regular expression mode) you can use this expression:

    • Search: ([^\n]*\n?){7}
    • Replace: $1

P.S. If you want another nth line, just replace the number between the braces.

like image 89
durban Avatar answered Oct 29 '25 08:10

durban



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!