1

I need to delete all the lines from around 30000 files and leave only a specific line (number 272). The content of the line is different for each file (string of numbers). I've spent quite some time on this now and cannot see any functionality that would allow me to do this. Are there any plugins that could help?

  • 4
    Notepad++ is probably not the right tool for this. A PowerShell script would be easier. A PowerShell expert will hopefully come along and give some hints. – DavidPostill Apr 21 '16 at 20:19
  • stackoverflow.com/questions/744094/… this might be enough to get you going. – kazoni Apr 21 '16 at 20:55
-1

As @DavidPostill suggests, Notepad++ is not the tool to do this job.

Instead, I would suggest (as he did) that you use a scripting language of some kind to iterate thru the files, then iterate thru the lines, and save the single wanted line to a new file.

Here's a PowerShell script that will do that:

# Set by user to their needs.
$filesToCheck = "c:\pathToFiles\*.txt"
$lineToKeep = 272

# Gather list of files based on the path (and mask) provided by user.
$files = gci $filesToCheck

# Iterate over each file.
foreach ($file in $files) {

    # Load the content of the current file.
    $contents = Get-Content $file

    # Iterate over each line in the current file.
    for ($i = 0; $i -le ($contents.Length - 1); $i++) {

        # Are we on the line that the user wants to keep?
        if ($i -eq ($lineToKeep - 1)) {

            # Create a new file to hold the line.
            $newName = "$($file.Basename)-New.txt"
            # Write the current line to the file.
            $contents[$i] | Out-File $newName
        }
    }
}
  • This isn't an answer to the question about how to use Notepad++ – SteveC Jul 11 '17 at 8:55
  • 1
    @SteveC That's because Notepad++ can't do it. If you manage to figure out a way, please feel free to come back and add an answer. – Ƭᴇcʜιᴇ007 Jul 11 '17 at 16:16
-1

you could also you unix tools (with cygwin) to process one file

head -n 272 file | tail -1 > file

You can also write a python script and use it in the npp plugin http://npppythonscript.sourceforge.net/

Lots of solutions are possible

  • This isn't an answer to the question about how to use Notepad++ – SteveC Jul 11 '17 at 8:54
  • 1
    Yes it is : You can write a python script and use it in the npp python script plugin website. It's a very good plugin, I use it every day. – Christophe Meriaux Jul 12 '17 at 9:55
  • Yes, but you've not actually answered the question ... the first suggestion is about using different tools, the second also isn't an actual answer, just telling the person to do "something". Give an actual Python script and I'd vote for your answer – SteveC Jul 12 '17 at 10:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.