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

10,011

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.

Share:
10,011
Admin
Author by

Admin

Updated on June 13, 2022

Comments

  • Admin
    Admin almost 2 years

    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.