Delete all lines in Notepad++ except lines containing a word I need?












184















I have a text file and want to keep lines started with <Path>, and delete all the other lines.



How can I do it?










share|improve this question















migrated from stackoverflow.com May 29 '11 at 16:46


This question came from our site for professional and enthusiast programmers.



















  • Related: stackoverflow.com/questions/8264391/…

    – Cees Timmerman
    May 30 '16 at 15:55











  • The LineFilter2 plugin is also easy to use.

    – Karsten
    Mar 31 '17 at 10:00
















184















I have a text file and want to keep lines started with <Path>, and delete all the other lines.



How can I do it?










share|improve this question















migrated from stackoverflow.com May 29 '11 at 16:46


This question came from our site for professional and enthusiast programmers.



















  • Related: stackoverflow.com/questions/8264391/…

    – Cees Timmerman
    May 30 '16 at 15:55











  • The LineFilter2 plugin is also easy to use.

    – Karsten
    Mar 31 '17 at 10:00














184












184








184


69






I have a text file and want to keep lines started with <Path>, and delete all the other lines.



How can I do it?










share|improve this question
















I have a text file and want to keep lines started with <Path>, and delete all the other lines.



How can I do it?







notepad++






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 13 '17 at 11:18









wonea

1,48211940




1,48211940










asked May 29 '11 at 15:05







alon











migrated from stackoverflow.com May 29 '11 at 16:46


This question came from our site for professional and enthusiast programmers.









migrated from stackoverflow.com May 29 '11 at 16:46


This question came from our site for professional and enthusiast programmers.















  • Related: stackoverflow.com/questions/8264391/…

    – Cees Timmerman
    May 30 '16 at 15:55











  • The LineFilter2 plugin is also easy to use.

    – Karsten
    Mar 31 '17 at 10:00



















  • Related: stackoverflow.com/questions/8264391/…

    – Cees Timmerman
    May 30 '16 at 15:55











  • The LineFilter2 plugin is also easy to use.

    – Karsten
    Mar 31 '17 at 10:00

















Related: stackoverflow.com/questions/8264391/…

– Cees Timmerman
May 30 '16 at 15:55





Related: stackoverflow.com/questions/8264391/…

– Cees Timmerman
May 30 '16 at 15:55













The LineFilter2 plugin is also easy to use.

– Karsten
Mar 31 '17 at 10:00





The LineFilter2 plugin is also easy to use.

– Karsten
Mar 31 '17 at 10:00










10 Answers
10






active

oldest

votes


















271














There is an easy way to achieve this. You need to perform 3 steps.





  1. Go to Search menu > Find... > Select "Mark" Tab. Activate regular expressions. Search for ^<Path> (^ is for line start). Don't forget to check "Bookmark lines" and Press "Mark All"



    ==> All Rows you want to keep got a Bookmark




  2. Go to Menu "Search - Bookmark - Inverse Bookmark"



    ==> All Line you want to delete are bookmarked.




  3. Go to Menu "Search - Bookmark - Remove Bookmarked lines"



    ==> All Bookmarked lines are deleted.








share|improve this answer





















  • 41





    +1. Nice, didn't know about this. There are also options to "Remove unmarked lines" or "Cut/copy marked lines" that can save some time.

    – deizel
    Oct 10 '11 at 11:31






  • 5





    I had troubles at first because my version (6.2.3) of Notepad++ doesn't have a menu item named "Mark Tab". Instead, you have to go to "Search" -> "Find..." -> click on the tab "Mark". And you no longer have to inverse the bookmarks. Notepad++ now has "Remove Unmarked Lines". But your tip helped me a lot! Thanks!

    – Adam
    Feb 7 '13 at 14:14








  • 20





    You can skip step 2, because it is (at least since v6.4.5) possible to choose "Remove Unmarked Lines".

    – Julian
    Sep 27 '13 at 11:00






  • 4





    I'm using Notepad++ for so long and I've never known what are 'Bookmarks' before. Amazing how powerful that tool is and how little I know about it.

    – Danubian Sailor
    Nov 19 '14 at 10:44











  • You are a genious. this is just another shocking example of how to get to know the tool you use for real.

    – Marcello Grechi Lins
    Jun 23 '16 at 14:54



















61














This can actually be done in two steps as of 6.3. I think it can be done earlier than that as I had 5.9 when I first tried it.



Using stema's post as the basis of this answer. There's one less step now. Mark lines and remove unmarked lines. Done. Detailed instructions follow.





  1. Search menu "Find". In the Find dialog, click the "Mark" tab. Activate regular expressions. Search for ^<Path> (^ is for line start). Don't forget to check "Bookmark lines" and Press "Mark All"



    ==> All Rows you want to keep now have a Bookmark




  2. Search Menu -> Bookmark -> Remove Unmarked Lines.



    ==> All NON Bookmarked lines are deleted.








share|improve this answer





















  • 2





    This took me 10 seconds while the other solution took me >20 seconds. Thx!

    – Black
    Jul 26 '16 at 11:25



















27














Clean regex only solution



Two step variant





  1. regex replace



    (?!^.*test.*$)^.+


    replace test with your requested text




  2. replace



    [rn]{2,}


    with rn




Single step variant



Use ^(?!<Path>).*rn to replace matches with empty string. Generalized version would be ^(?!.*?test).*rn. This won't remove empty line at the end of the file. All other lines are removed, including multiple consecutive empty lines.



Explanation:




  1. (?!) is a negative look up. ^.*test.*$ selects the whole line that contains the requested text.


  2. [rn]{2,} matches any rn that occurs more then once this is Windows New line. if you have Linux or another operating system you might need to mess with this. the second is to replace it with one return line.







share|improve this answer





















  • 1





    Note to the peoples: Sometimes regex with end of line (EOL) "doesn't work". The rn EOL mentioned in the post is what Windows uses and therefore may or may not be what you are looking for. Often on Linux environments it's just n, or in Mac environments just r, so if you pull a file from either, it won't be Windows style EOL. However, if you download via FileZilla and ASCII mode triggers, it may change them back into Windows EOL (like n into rn). So if regex is not working, check the EOL style by going to "View > Show Symbols > Show End Of Line". CR = r. LF = n.

    – dhaupin
    Dec 13 '16 at 15:02





















5














It seems to me that the easiest way is to just use the "Find All in Current Document" feature and then either copy the results into a new file or select all and replace in the current one.



This would find all lines containing your text and list them at the bottom. Just right click on the search result and copy / paste.






share|improve this answer
























  • You do have to remove the line numbers by replacing tLine [d]*: . Still a great answer.

    – Noumenon
    Jan 10 '17 at 21:21



















4














Go to menu Search -> Find... -> Activate regular expressions. Search for "^Path" (^ is for line start).



Click on the "Find all in Current Document" button.



The "Find result" window will appear with all the lines the the pattern. Select copy/paste them to a new tab in Notepad++.



In this new tab, got to: menu Search -> Replace... -> Activate regular expressions.



In the "Find what:" field, use the pattern: "Line d+: ". Leave the "Replace with:" field blank.



Click on the "Replace all" button.






share|improve this answer

































    3














    Providing that you actually want to match <Path> and not a file system path, you can try this from a command line using Perl:



    perl -pe " if ($_ !~ /<Path>/) { s/$_// } " < in.txt > out.txt


    It worked with Strawberry Perl on Windows, so adjust accordingly if the results are not what you expect.






    share|improve this answer

































      3














      It is clumsy, but copy it all to Excel, and then use =IF(LEFT(A1,6)="<Path>",A1,"") and copy that formula all the way down. Then copy that back to Notepad++. It's not ideal, but it's pretty easy (if you have Excel). Warning: It will not work well with indented lines (Excel will shift the columns, etc.).






      share|improve this answer


























      • When there are a number of ways to handle this task directly, why would you want to destructively copy into another application, process there, and transfer back?

        – Baldrickk
        Feb 15 '17 at 16:36



















      1














      There is no easy way to do what you want with Notepad++. You'll need to either download a program to your computer or script something in VB (I assume you're on Windows).



      You can do what you want one of two ways with sed. The sed utility is a favorite on *nix and can be found for Windows from the great people at GnuWin (http://gnuwin32.sourceforge.net/packages/sed.htm). You would download this program, and then run your command from the command prompt.



      Delete all lines not containing :
      sed -i '/^<PATH>/!d' file



      Print all lines containing to a new file:
      sed -n '/^<PATH>/p' file > newfile



      I suggest you use print the lines you want to a new file. The reason for this is that you probably won't get the regex statement for the first time around. The sed utility uses Regular Expression Basic Syntax (view the reference at http://www.regular-expressions.info/reference.html). If is something like a *nix path (/var/www) then you'll need to escape the / character for your regex to work.



      Example: sed -n '/^/var/www/p' file > newfile

      This will print out all lines that start with '/var/www'. If I filed to escape the / character, then the command would have thrown an error. You can escape a special character (such as /) with the backslash character .






      share|improve this answer


























      • This may be an old answer but since it actually unbelievably has 2 votes (-1 now from me) wanted to comment on not only how wrong it is, but reiterate in a SINGLE command operation how I just (again) took a >100k line log file down to the 34 lines containing the one word (or phrase) in this case simply "error" in under 3 seconds by simply placing this regex in the FIND WHAT: ^(?!.*?error).*rn and leaving REPLACE WITH blank, and do NOT select the ". matches newline" and click "REPLACE ALL". Yes I also love sed and awk but saying NPP cannot do this is just false.

        – Collin Chaffin
        Dec 30 '18 at 18:53



















      1














      Better solution with regex replace:



      (?!^.*SOMETEXT.*$)^.+r?n


      And replace with nothing






      share|improve this answer
























      • Welcome to Super User! Care to explain this for those who might not know what each bit of the regex does? :)

        – bertieb
        May 1 '18 at 15:47



















      0














      Use Search->Replace and enter a regular expression like ^[^ ].* and replace all with an empty string using Regular expression. Next step is to find empty lines searching for nn replacing with n using Extended multiple times until 0 occurrences were found. (use rnrn and rn depending on file format). If you have very many empty lines in a row, it is quickier to use nnnnnnn or even more n:s in the search string.






      share|improve this answer























        Your Answer








        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "3"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














        draft saved

        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f290247%2fdelete-all-lines-in-notepad-except-lines-containing-a-word-i-need%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown
























        10 Answers
        10






        active

        oldest

        votes








        10 Answers
        10






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        271














        There is an easy way to achieve this. You need to perform 3 steps.





        1. Go to Search menu > Find... > Select "Mark" Tab. Activate regular expressions. Search for ^<Path> (^ is for line start). Don't forget to check "Bookmark lines" and Press "Mark All"



          ==> All Rows you want to keep got a Bookmark




        2. Go to Menu "Search - Bookmark - Inverse Bookmark"



          ==> All Line you want to delete are bookmarked.




        3. Go to Menu "Search - Bookmark - Remove Bookmarked lines"



          ==> All Bookmarked lines are deleted.








        share|improve this answer





















        • 41





          +1. Nice, didn't know about this. There are also options to "Remove unmarked lines" or "Cut/copy marked lines" that can save some time.

          – deizel
          Oct 10 '11 at 11:31






        • 5





          I had troubles at first because my version (6.2.3) of Notepad++ doesn't have a menu item named "Mark Tab". Instead, you have to go to "Search" -> "Find..." -> click on the tab "Mark". And you no longer have to inverse the bookmarks. Notepad++ now has "Remove Unmarked Lines". But your tip helped me a lot! Thanks!

          – Adam
          Feb 7 '13 at 14:14








        • 20





          You can skip step 2, because it is (at least since v6.4.5) possible to choose "Remove Unmarked Lines".

          – Julian
          Sep 27 '13 at 11:00






        • 4





          I'm using Notepad++ for so long and I've never known what are 'Bookmarks' before. Amazing how powerful that tool is and how little I know about it.

          – Danubian Sailor
          Nov 19 '14 at 10:44











        • You are a genious. this is just another shocking example of how to get to know the tool you use for real.

          – Marcello Grechi Lins
          Jun 23 '16 at 14:54
















        271














        There is an easy way to achieve this. You need to perform 3 steps.





        1. Go to Search menu > Find... > Select "Mark" Tab. Activate regular expressions. Search for ^<Path> (^ is for line start). Don't forget to check "Bookmark lines" and Press "Mark All"



          ==> All Rows you want to keep got a Bookmark




        2. Go to Menu "Search - Bookmark - Inverse Bookmark"



          ==> All Line you want to delete are bookmarked.




        3. Go to Menu "Search - Bookmark - Remove Bookmarked lines"



          ==> All Bookmarked lines are deleted.








        share|improve this answer





















        • 41





          +1. Nice, didn't know about this. There are also options to "Remove unmarked lines" or "Cut/copy marked lines" that can save some time.

          – deizel
          Oct 10 '11 at 11:31






        • 5





          I had troubles at first because my version (6.2.3) of Notepad++ doesn't have a menu item named "Mark Tab". Instead, you have to go to "Search" -> "Find..." -> click on the tab "Mark". And you no longer have to inverse the bookmarks. Notepad++ now has "Remove Unmarked Lines". But your tip helped me a lot! Thanks!

          – Adam
          Feb 7 '13 at 14:14








        • 20





          You can skip step 2, because it is (at least since v6.4.5) possible to choose "Remove Unmarked Lines".

          – Julian
          Sep 27 '13 at 11:00






        • 4





          I'm using Notepad++ for so long and I've never known what are 'Bookmarks' before. Amazing how powerful that tool is and how little I know about it.

          – Danubian Sailor
          Nov 19 '14 at 10:44











        • You are a genious. this is just another shocking example of how to get to know the tool you use for real.

          – Marcello Grechi Lins
          Jun 23 '16 at 14:54














        271












        271








        271







        There is an easy way to achieve this. You need to perform 3 steps.





        1. Go to Search menu > Find... > Select "Mark" Tab. Activate regular expressions. Search for ^<Path> (^ is for line start). Don't forget to check "Bookmark lines" and Press "Mark All"



          ==> All Rows you want to keep got a Bookmark




        2. Go to Menu "Search - Bookmark - Inverse Bookmark"



          ==> All Line you want to delete are bookmarked.




        3. Go to Menu "Search - Bookmark - Remove Bookmarked lines"



          ==> All Bookmarked lines are deleted.








        share|improve this answer















        There is an easy way to achieve this. You need to perform 3 steps.





        1. Go to Search menu > Find... > Select "Mark" Tab. Activate regular expressions. Search for ^<Path> (^ is for line start). Don't forget to check "Bookmark lines" and Press "Mark All"



          ==> All Rows you want to keep got a Bookmark




        2. Go to Menu "Search - Bookmark - Inverse Bookmark"



          ==> All Line you want to delete are bookmarked.




        3. Go to Menu "Search - Bookmark - Remove Bookmarked lines"



          ==> All Bookmarked lines are deleted.









        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jun 15 '13 at 14:07









        fool4jesus

        1034




        1034










        answered Jun 3 '11 at 20:23









        stemastema

        3,1141119




        3,1141119








        • 41





          +1. Nice, didn't know about this. There are also options to "Remove unmarked lines" or "Cut/copy marked lines" that can save some time.

          – deizel
          Oct 10 '11 at 11:31






        • 5





          I had troubles at first because my version (6.2.3) of Notepad++ doesn't have a menu item named "Mark Tab". Instead, you have to go to "Search" -> "Find..." -> click on the tab "Mark". And you no longer have to inverse the bookmarks. Notepad++ now has "Remove Unmarked Lines". But your tip helped me a lot! Thanks!

          – Adam
          Feb 7 '13 at 14:14








        • 20





          You can skip step 2, because it is (at least since v6.4.5) possible to choose "Remove Unmarked Lines".

          – Julian
          Sep 27 '13 at 11:00






        • 4





          I'm using Notepad++ for so long and I've never known what are 'Bookmarks' before. Amazing how powerful that tool is and how little I know about it.

          – Danubian Sailor
          Nov 19 '14 at 10:44











        • You are a genious. this is just another shocking example of how to get to know the tool you use for real.

          – Marcello Grechi Lins
          Jun 23 '16 at 14:54














        • 41





          +1. Nice, didn't know about this. There are also options to "Remove unmarked lines" or "Cut/copy marked lines" that can save some time.

          – deizel
          Oct 10 '11 at 11:31






        • 5





          I had troubles at first because my version (6.2.3) of Notepad++ doesn't have a menu item named "Mark Tab". Instead, you have to go to "Search" -> "Find..." -> click on the tab "Mark". And you no longer have to inverse the bookmarks. Notepad++ now has "Remove Unmarked Lines". But your tip helped me a lot! Thanks!

          – Adam
          Feb 7 '13 at 14:14








        • 20





          You can skip step 2, because it is (at least since v6.4.5) possible to choose "Remove Unmarked Lines".

          – Julian
          Sep 27 '13 at 11:00






        • 4





          I'm using Notepad++ for so long and I've never known what are 'Bookmarks' before. Amazing how powerful that tool is and how little I know about it.

          – Danubian Sailor
          Nov 19 '14 at 10:44











        • You are a genious. this is just another shocking example of how to get to know the tool you use for real.

          – Marcello Grechi Lins
          Jun 23 '16 at 14:54








        41




        41





        +1. Nice, didn't know about this. There are also options to "Remove unmarked lines" or "Cut/copy marked lines" that can save some time.

        – deizel
        Oct 10 '11 at 11:31





        +1. Nice, didn't know about this. There are also options to "Remove unmarked lines" or "Cut/copy marked lines" that can save some time.

        – deizel
        Oct 10 '11 at 11:31




        5




        5





        I had troubles at first because my version (6.2.3) of Notepad++ doesn't have a menu item named "Mark Tab". Instead, you have to go to "Search" -> "Find..." -> click on the tab "Mark". And you no longer have to inverse the bookmarks. Notepad++ now has "Remove Unmarked Lines". But your tip helped me a lot! Thanks!

        – Adam
        Feb 7 '13 at 14:14







        I had troubles at first because my version (6.2.3) of Notepad++ doesn't have a menu item named "Mark Tab". Instead, you have to go to "Search" -> "Find..." -> click on the tab "Mark". And you no longer have to inverse the bookmarks. Notepad++ now has "Remove Unmarked Lines". But your tip helped me a lot! Thanks!

        – Adam
        Feb 7 '13 at 14:14






        20




        20





        You can skip step 2, because it is (at least since v6.4.5) possible to choose "Remove Unmarked Lines".

        – Julian
        Sep 27 '13 at 11:00





        You can skip step 2, because it is (at least since v6.4.5) possible to choose "Remove Unmarked Lines".

        – Julian
        Sep 27 '13 at 11:00




        4




        4





        I'm using Notepad++ for so long and I've never known what are 'Bookmarks' before. Amazing how powerful that tool is and how little I know about it.

        – Danubian Sailor
        Nov 19 '14 at 10:44





        I'm using Notepad++ for so long and I've never known what are 'Bookmarks' before. Amazing how powerful that tool is and how little I know about it.

        – Danubian Sailor
        Nov 19 '14 at 10:44













        You are a genious. this is just another shocking example of how to get to know the tool you use for real.

        – Marcello Grechi Lins
        Jun 23 '16 at 14:54





        You are a genious. this is just another shocking example of how to get to know the tool you use for real.

        – Marcello Grechi Lins
        Jun 23 '16 at 14:54













        61














        This can actually be done in two steps as of 6.3. I think it can be done earlier than that as I had 5.9 when I first tried it.



        Using stema's post as the basis of this answer. There's one less step now. Mark lines and remove unmarked lines. Done. Detailed instructions follow.





        1. Search menu "Find". In the Find dialog, click the "Mark" tab. Activate regular expressions. Search for ^<Path> (^ is for line start). Don't forget to check "Bookmark lines" and Press "Mark All"



          ==> All Rows you want to keep now have a Bookmark




        2. Search Menu -> Bookmark -> Remove Unmarked Lines.



          ==> All NON Bookmarked lines are deleted.








        share|improve this answer





















        • 2





          This took me 10 seconds while the other solution took me >20 seconds. Thx!

          – Black
          Jul 26 '16 at 11:25
















        61














        This can actually be done in two steps as of 6.3. I think it can be done earlier than that as I had 5.9 when I first tried it.



        Using stema's post as the basis of this answer. There's one less step now. Mark lines and remove unmarked lines. Done. Detailed instructions follow.





        1. Search menu "Find". In the Find dialog, click the "Mark" tab. Activate regular expressions. Search for ^<Path> (^ is for line start). Don't forget to check "Bookmark lines" and Press "Mark All"



          ==> All Rows you want to keep now have a Bookmark




        2. Search Menu -> Bookmark -> Remove Unmarked Lines.



          ==> All NON Bookmarked lines are deleted.








        share|improve this answer





















        • 2





          This took me 10 seconds while the other solution took me >20 seconds. Thx!

          – Black
          Jul 26 '16 at 11:25














        61












        61








        61







        This can actually be done in two steps as of 6.3. I think it can be done earlier than that as I had 5.9 when I first tried it.



        Using stema's post as the basis of this answer. There's one less step now. Mark lines and remove unmarked lines. Done. Detailed instructions follow.





        1. Search menu "Find". In the Find dialog, click the "Mark" tab. Activate regular expressions. Search for ^<Path> (^ is for line start). Don't forget to check "Bookmark lines" and Press "Mark All"



          ==> All Rows you want to keep now have a Bookmark




        2. Search Menu -> Bookmark -> Remove Unmarked Lines.



          ==> All NON Bookmarked lines are deleted.








        share|improve this answer















        This can actually be done in two steps as of 6.3. I think it can be done earlier than that as I had 5.9 when I first tried it.



        Using stema's post as the basis of this answer. There's one less step now. Mark lines and remove unmarked lines. Done. Detailed instructions follow.





        1. Search menu "Find". In the Find dialog, click the "Mark" tab. Activate regular expressions. Search for ^<Path> (^ is for line start). Don't forget to check "Bookmark lines" and Press "Mark All"



          ==> All Rows you want to keep now have a Bookmark




        2. Search Menu -> Bookmark -> Remove Unmarked Lines.



          ==> All NON Bookmarked lines are deleted.









        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Feb 11 at 18:46









        Justin

        14318




        14318










        answered Feb 27 '13 at 16:03









        RecognizerRecognizer

        7481614




        7481614








        • 2





          This took me 10 seconds while the other solution took me >20 seconds. Thx!

          – Black
          Jul 26 '16 at 11:25














        • 2





          This took me 10 seconds while the other solution took me >20 seconds. Thx!

          – Black
          Jul 26 '16 at 11:25








        2




        2





        This took me 10 seconds while the other solution took me >20 seconds. Thx!

        – Black
        Jul 26 '16 at 11:25





        This took me 10 seconds while the other solution took me >20 seconds. Thx!

        – Black
        Jul 26 '16 at 11:25











        27














        Clean regex only solution



        Two step variant





        1. regex replace



          (?!^.*test.*$)^.+


          replace test with your requested text




        2. replace



          [rn]{2,}


          with rn




        Single step variant



        Use ^(?!<Path>).*rn to replace matches with empty string. Generalized version would be ^(?!.*?test).*rn. This won't remove empty line at the end of the file. All other lines are removed, including multiple consecutive empty lines.



        Explanation:




        1. (?!) is a negative look up. ^.*test.*$ selects the whole line that contains the requested text.


        2. [rn]{2,} matches any rn that occurs more then once this is Windows New line. if you have Linux or another operating system you might need to mess with this. the second is to replace it with one return line.







        share|improve this answer





















        • 1





          Note to the peoples: Sometimes regex with end of line (EOL) "doesn't work". The rn EOL mentioned in the post is what Windows uses and therefore may or may not be what you are looking for. Often on Linux environments it's just n, or in Mac environments just r, so if you pull a file from either, it won't be Windows style EOL. However, if you download via FileZilla and ASCII mode triggers, it may change them back into Windows EOL (like n into rn). So if regex is not working, check the EOL style by going to "View > Show Symbols > Show End Of Line". CR = r. LF = n.

          – dhaupin
          Dec 13 '16 at 15:02


















        27














        Clean regex only solution



        Two step variant





        1. regex replace



          (?!^.*test.*$)^.+


          replace test with your requested text




        2. replace



          [rn]{2,}


          with rn




        Single step variant



        Use ^(?!<Path>).*rn to replace matches with empty string. Generalized version would be ^(?!.*?test).*rn. This won't remove empty line at the end of the file. All other lines are removed, including multiple consecutive empty lines.



        Explanation:




        1. (?!) is a negative look up. ^.*test.*$ selects the whole line that contains the requested text.


        2. [rn]{2,} matches any rn that occurs more then once this is Windows New line. if you have Linux or another operating system you might need to mess with this. the second is to replace it with one return line.







        share|improve this answer





















        • 1





          Note to the peoples: Sometimes regex with end of line (EOL) "doesn't work". The rn EOL mentioned in the post is what Windows uses and therefore may or may not be what you are looking for. Often on Linux environments it's just n, or in Mac environments just r, so if you pull a file from either, it won't be Windows style EOL. However, if you download via FileZilla and ASCII mode triggers, it may change them back into Windows EOL (like n into rn). So if regex is not working, check the EOL style by going to "View > Show Symbols > Show End Of Line". CR = r. LF = n.

          – dhaupin
          Dec 13 '16 at 15:02
















        27












        27








        27







        Clean regex only solution



        Two step variant





        1. regex replace



          (?!^.*test.*$)^.+


          replace test with your requested text




        2. replace



          [rn]{2,}


          with rn




        Single step variant



        Use ^(?!<Path>).*rn to replace matches with empty string. Generalized version would be ^(?!.*?test).*rn. This won't remove empty line at the end of the file. All other lines are removed, including multiple consecutive empty lines.



        Explanation:




        1. (?!) is a negative look up. ^.*test.*$ selects the whole line that contains the requested text.


        2. [rn]{2,} matches any rn that occurs more then once this is Windows New line. if you have Linux or another operating system you might need to mess with this. the second is to replace it with one return line.







        share|improve this answer















        Clean regex only solution



        Two step variant





        1. regex replace



          (?!^.*test.*$)^.+


          replace test with your requested text




        2. replace



          [rn]{2,}


          with rn




        Single step variant



        Use ^(?!<Path>).*rn to replace matches with empty string. Generalized version would be ^(?!.*?test).*rn. This won't remove empty line at the end of the file. All other lines are removed, including multiple consecutive empty lines.



        Explanation:




        1. (?!) is a negative look up. ^.*test.*$ selects the whole line that contains the requested text.


        2. [rn]{2,} matches any rn that occurs more then once this is Windows New line. if you have Linux or another operating system you might need to mess with this. the second is to replace it with one return line.








        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Dec 17 '15 at 16:31









        Vlastimil Ovčáčík

        1,56211025




        1,56211025










        answered Jul 8 '13 at 16:51









        sonar0msonar0m

        37132




        37132








        • 1





          Note to the peoples: Sometimes regex with end of line (EOL) "doesn't work". The rn EOL mentioned in the post is what Windows uses and therefore may or may not be what you are looking for. Often on Linux environments it's just n, or in Mac environments just r, so if you pull a file from either, it won't be Windows style EOL. However, if you download via FileZilla and ASCII mode triggers, it may change them back into Windows EOL (like n into rn). So if regex is not working, check the EOL style by going to "View > Show Symbols > Show End Of Line". CR = r. LF = n.

          – dhaupin
          Dec 13 '16 at 15:02
















        • 1





          Note to the peoples: Sometimes regex with end of line (EOL) "doesn't work". The rn EOL mentioned in the post is what Windows uses and therefore may or may not be what you are looking for. Often on Linux environments it's just n, or in Mac environments just r, so if you pull a file from either, it won't be Windows style EOL. However, if you download via FileZilla and ASCII mode triggers, it may change them back into Windows EOL (like n into rn). So if regex is not working, check the EOL style by going to "View > Show Symbols > Show End Of Line". CR = r. LF = n.

          – dhaupin
          Dec 13 '16 at 15:02










        1




        1





        Note to the peoples: Sometimes regex with end of line (EOL) "doesn't work". The rn EOL mentioned in the post is what Windows uses and therefore may or may not be what you are looking for. Often on Linux environments it's just n, or in Mac environments just r, so if you pull a file from either, it won't be Windows style EOL. However, if you download via FileZilla and ASCII mode triggers, it may change them back into Windows EOL (like n into rn). So if regex is not working, check the EOL style by going to "View > Show Symbols > Show End Of Line". CR = r. LF = n.

        – dhaupin
        Dec 13 '16 at 15:02







        Note to the peoples: Sometimes regex with end of line (EOL) "doesn't work". The rn EOL mentioned in the post is what Windows uses and therefore may or may not be what you are looking for. Often on Linux environments it's just n, or in Mac environments just r, so if you pull a file from either, it won't be Windows style EOL. However, if you download via FileZilla and ASCII mode triggers, it may change them back into Windows EOL (like n into rn). So if regex is not working, check the EOL style by going to "View > Show Symbols > Show End Of Line". CR = r. LF = n.

        – dhaupin
        Dec 13 '16 at 15:02













        5














        It seems to me that the easiest way is to just use the "Find All in Current Document" feature and then either copy the results into a new file or select all and replace in the current one.



        This would find all lines containing your text and list them at the bottom. Just right click on the search result and copy / paste.






        share|improve this answer
























        • You do have to remove the line numbers by replacing tLine [d]*: . Still a great answer.

          – Noumenon
          Jan 10 '17 at 21:21
















        5














        It seems to me that the easiest way is to just use the "Find All in Current Document" feature and then either copy the results into a new file or select all and replace in the current one.



        This would find all lines containing your text and list them at the bottom. Just right click on the search result and copy / paste.






        share|improve this answer
























        • You do have to remove the line numbers by replacing tLine [d]*: . Still a great answer.

          – Noumenon
          Jan 10 '17 at 21:21














        5












        5








        5







        It seems to me that the easiest way is to just use the "Find All in Current Document" feature and then either copy the results into a new file or select all and replace in the current one.



        This would find all lines containing your text and list them at the bottom. Just right click on the search result and copy / paste.






        share|improve this answer













        It seems to me that the easiest way is to just use the "Find All in Current Document" feature and then either copy the results into a new file or select all and replace in the current one.



        This would find all lines containing your text and list them at the bottom. Just right click on the search result and copy / paste.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 17 '15 at 11:43









        GubbinsGubbins

        6111




        6111













        • You do have to remove the line numbers by replacing tLine [d]*: . Still a great answer.

          – Noumenon
          Jan 10 '17 at 21:21



















        • You do have to remove the line numbers by replacing tLine [d]*: . Still a great answer.

          – Noumenon
          Jan 10 '17 at 21:21

















        You do have to remove the line numbers by replacing tLine [d]*: . Still a great answer.

        – Noumenon
        Jan 10 '17 at 21:21





        You do have to remove the line numbers by replacing tLine [d]*: . Still a great answer.

        – Noumenon
        Jan 10 '17 at 21:21











        4














        Go to menu Search -> Find... -> Activate regular expressions. Search for "^Path" (^ is for line start).



        Click on the "Find all in Current Document" button.



        The "Find result" window will appear with all the lines the the pattern. Select copy/paste them to a new tab in Notepad++.



        In this new tab, got to: menu Search -> Replace... -> Activate regular expressions.



        In the "Find what:" field, use the pattern: "Line d+: ". Leave the "Replace with:" field blank.



        Click on the "Replace all" button.






        share|improve this answer






























          4














          Go to menu Search -> Find... -> Activate regular expressions. Search for "^Path" (^ is for line start).



          Click on the "Find all in Current Document" button.



          The "Find result" window will appear with all the lines the the pattern. Select copy/paste them to a new tab in Notepad++.



          In this new tab, got to: menu Search -> Replace... -> Activate regular expressions.



          In the "Find what:" field, use the pattern: "Line d+: ". Leave the "Replace with:" field blank.



          Click on the "Replace all" button.






          share|improve this answer




























            4












            4








            4







            Go to menu Search -> Find... -> Activate regular expressions. Search for "^Path" (^ is for line start).



            Click on the "Find all in Current Document" button.



            The "Find result" window will appear with all the lines the the pattern. Select copy/paste them to a new tab in Notepad++.



            In this new tab, got to: menu Search -> Replace... -> Activate regular expressions.



            In the "Find what:" field, use the pattern: "Line d+: ". Leave the "Replace with:" field blank.



            Click on the "Replace all" button.






            share|improve this answer















            Go to menu Search -> Find... -> Activate regular expressions. Search for "^Path" (^ is for line start).



            Click on the "Find all in Current Document" button.



            The "Find result" window will appear with all the lines the the pattern. Select copy/paste them to a new tab in Notepad++.



            In this new tab, got to: menu Search -> Replace... -> Activate regular expressions.



            In the "Find what:" field, use the pattern: "Line d+: ". Leave the "Replace with:" field blank.



            Click on the "Replace all" button.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited May 4 '14 at 21:15









            Peter Mortensen

            8,376166185




            8,376166185










            answered Jun 21 '13 at 16:36









            LuisLuis

            411




            411























                3














                Providing that you actually want to match <Path> and not a file system path, you can try this from a command line using Perl:



                perl -pe " if ($_ !~ /<Path>/) { s/$_// } " < in.txt > out.txt


                It worked with Strawberry Perl on Windows, so adjust accordingly if the results are not what you expect.






                share|improve this answer






























                  3














                  Providing that you actually want to match <Path> and not a file system path, you can try this from a command line using Perl:



                  perl -pe " if ($_ !~ /<Path>/) { s/$_// } " < in.txt > out.txt


                  It worked with Strawberry Perl on Windows, so adjust accordingly if the results are not what you expect.






                  share|improve this answer




























                    3












                    3








                    3







                    Providing that you actually want to match <Path> and not a file system path, you can try this from a command line using Perl:



                    perl -pe " if ($_ !~ /<Path>/) { s/$_// } " < in.txt > out.txt


                    It worked with Strawberry Perl on Windows, so adjust accordingly if the results are not what you expect.






                    share|improve this answer















                    Providing that you actually want to match <Path> and not a file system path, you can try this from a command line using Perl:



                    perl -pe " if ($_ !~ /<Path>/) { s/$_// } " < in.txt > out.txt


                    It worked with Strawberry Perl on Windows, so adjust accordingly if the results are not what you expect.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited May 30 '11 at 5:16

























                    answered May 30 '11 at 1:02









                    Joe InternetJoe Internet

                    4,99521313




                    4,99521313























                        3














                        It is clumsy, but copy it all to Excel, and then use =IF(LEFT(A1,6)="<Path>",A1,"") and copy that formula all the way down. Then copy that back to Notepad++. It's not ideal, but it's pretty easy (if you have Excel). Warning: It will not work well with indented lines (Excel will shift the columns, etc.).






                        share|improve this answer


























                        • When there are a number of ways to handle this task directly, why would you want to destructively copy into another application, process there, and transfer back?

                          – Baldrickk
                          Feb 15 '17 at 16:36
















                        3














                        It is clumsy, but copy it all to Excel, and then use =IF(LEFT(A1,6)="<Path>",A1,"") and copy that formula all the way down. Then copy that back to Notepad++. It's not ideal, but it's pretty easy (if you have Excel). Warning: It will not work well with indented lines (Excel will shift the columns, etc.).






                        share|improve this answer


























                        • When there are a number of ways to handle this task directly, why would you want to destructively copy into another application, process there, and transfer back?

                          – Baldrickk
                          Feb 15 '17 at 16:36














                        3












                        3








                        3







                        It is clumsy, but copy it all to Excel, and then use =IF(LEFT(A1,6)="<Path>",A1,"") and copy that formula all the way down. Then copy that back to Notepad++. It's not ideal, but it's pretty easy (if you have Excel). Warning: It will not work well with indented lines (Excel will shift the columns, etc.).






                        share|improve this answer















                        It is clumsy, but copy it all to Excel, and then use =IF(LEFT(A1,6)="<Path>",A1,"") and copy that formula all the way down. Then copy that back to Notepad++. It's not ideal, but it's pretty easy (if you have Excel). Warning: It will not work well with indented lines (Excel will shift the columns, etc.).







                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited May 4 '14 at 21:11









                        Peter Mortensen

                        8,376166185




                        8,376166185










                        answered May 29 '11 at 18:07









                        soandossoandos

                        20.3k2892131




                        20.3k2892131













                        • When there are a number of ways to handle this task directly, why would you want to destructively copy into another application, process there, and transfer back?

                          – Baldrickk
                          Feb 15 '17 at 16:36



















                        • When there are a number of ways to handle this task directly, why would you want to destructively copy into another application, process there, and transfer back?

                          – Baldrickk
                          Feb 15 '17 at 16:36

















                        When there are a number of ways to handle this task directly, why would you want to destructively copy into another application, process there, and transfer back?

                        – Baldrickk
                        Feb 15 '17 at 16:36





                        When there are a number of ways to handle this task directly, why would you want to destructively copy into another application, process there, and transfer back?

                        – Baldrickk
                        Feb 15 '17 at 16:36











                        1














                        There is no easy way to do what you want with Notepad++. You'll need to either download a program to your computer or script something in VB (I assume you're on Windows).



                        You can do what you want one of two ways with sed. The sed utility is a favorite on *nix and can be found for Windows from the great people at GnuWin (http://gnuwin32.sourceforge.net/packages/sed.htm). You would download this program, and then run your command from the command prompt.



                        Delete all lines not containing :
                        sed -i '/^<PATH>/!d' file



                        Print all lines containing to a new file:
                        sed -n '/^<PATH>/p' file > newfile



                        I suggest you use print the lines you want to a new file. The reason for this is that you probably won't get the regex statement for the first time around. The sed utility uses Regular Expression Basic Syntax (view the reference at http://www.regular-expressions.info/reference.html). If is something like a *nix path (/var/www) then you'll need to escape the / character for your regex to work.



                        Example: sed -n '/^/var/www/p' file > newfile

                        This will print out all lines that start with '/var/www'. If I filed to escape the / character, then the command would have thrown an error. You can escape a special character (such as /) with the backslash character .






                        share|improve this answer


























                        • This may be an old answer but since it actually unbelievably has 2 votes (-1 now from me) wanted to comment on not only how wrong it is, but reiterate in a SINGLE command operation how I just (again) took a >100k line log file down to the 34 lines containing the one word (or phrase) in this case simply "error" in under 3 seconds by simply placing this regex in the FIND WHAT: ^(?!.*?error).*rn and leaving REPLACE WITH blank, and do NOT select the ". matches newline" and click "REPLACE ALL". Yes I also love sed and awk but saying NPP cannot do this is just false.

                          – Collin Chaffin
                          Dec 30 '18 at 18:53
















                        1














                        There is no easy way to do what you want with Notepad++. You'll need to either download a program to your computer or script something in VB (I assume you're on Windows).



                        You can do what you want one of two ways with sed. The sed utility is a favorite on *nix and can be found for Windows from the great people at GnuWin (http://gnuwin32.sourceforge.net/packages/sed.htm). You would download this program, and then run your command from the command prompt.



                        Delete all lines not containing :
                        sed -i '/^<PATH>/!d' file



                        Print all lines containing to a new file:
                        sed -n '/^<PATH>/p' file > newfile



                        I suggest you use print the lines you want to a new file. The reason for this is that you probably won't get the regex statement for the first time around. The sed utility uses Regular Expression Basic Syntax (view the reference at http://www.regular-expressions.info/reference.html). If is something like a *nix path (/var/www) then you'll need to escape the / character for your regex to work.



                        Example: sed -n '/^/var/www/p' file > newfile

                        This will print out all lines that start with '/var/www'. If I filed to escape the / character, then the command would have thrown an error. You can escape a special character (such as /) with the backslash character .






                        share|improve this answer


























                        • This may be an old answer but since it actually unbelievably has 2 votes (-1 now from me) wanted to comment on not only how wrong it is, but reiterate in a SINGLE command operation how I just (again) took a >100k line log file down to the 34 lines containing the one word (or phrase) in this case simply "error" in under 3 seconds by simply placing this regex in the FIND WHAT: ^(?!.*?error).*rn and leaving REPLACE WITH blank, and do NOT select the ". matches newline" and click "REPLACE ALL". Yes I also love sed and awk but saying NPP cannot do this is just false.

                          – Collin Chaffin
                          Dec 30 '18 at 18:53














                        1












                        1








                        1







                        There is no easy way to do what you want with Notepad++. You'll need to either download a program to your computer or script something in VB (I assume you're on Windows).



                        You can do what you want one of two ways with sed. The sed utility is a favorite on *nix and can be found for Windows from the great people at GnuWin (http://gnuwin32.sourceforge.net/packages/sed.htm). You would download this program, and then run your command from the command prompt.



                        Delete all lines not containing :
                        sed -i '/^<PATH>/!d' file



                        Print all lines containing to a new file:
                        sed -n '/^<PATH>/p' file > newfile



                        I suggest you use print the lines you want to a new file. The reason for this is that you probably won't get the regex statement for the first time around. The sed utility uses Regular Expression Basic Syntax (view the reference at http://www.regular-expressions.info/reference.html). If is something like a *nix path (/var/www) then you'll need to escape the / character for your regex to work.



                        Example: sed -n '/^/var/www/p' file > newfile

                        This will print out all lines that start with '/var/www'. If I filed to escape the / character, then the command would have thrown an error. You can escape a special character (such as /) with the backslash character .






                        share|improve this answer















                        There is no easy way to do what you want with Notepad++. You'll need to either download a program to your computer or script something in VB (I assume you're on Windows).



                        You can do what you want one of two ways with sed. The sed utility is a favorite on *nix and can be found for Windows from the great people at GnuWin (http://gnuwin32.sourceforge.net/packages/sed.htm). You would download this program, and then run your command from the command prompt.



                        Delete all lines not containing :
                        sed -i '/^<PATH>/!d' file



                        Print all lines containing to a new file:
                        sed -n '/^<PATH>/p' file > newfile



                        I suggest you use print the lines you want to a new file. The reason for this is that you probably won't get the regex statement for the first time around. The sed utility uses Regular Expression Basic Syntax (view the reference at http://www.regular-expressions.info/reference.html). If is something like a *nix path (/var/www) then you'll need to escape the / character for your regex to work.



                        Example: sed -n '/^/var/www/p' file > newfile

                        This will print out all lines that start with '/var/www'. If I filed to escape the / character, then the command would have thrown an error. You can escape a special character (such as /) with the backslash character .







                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited May 30 '11 at 5:31

























                        answered May 30 '11 at 3:00









                        Chris TingChris Ting

                        1,50186




                        1,50186













                        • This may be an old answer but since it actually unbelievably has 2 votes (-1 now from me) wanted to comment on not only how wrong it is, but reiterate in a SINGLE command operation how I just (again) took a >100k line log file down to the 34 lines containing the one word (or phrase) in this case simply "error" in under 3 seconds by simply placing this regex in the FIND WHAT: ^(?!.*?error).*rn and leaving REPLACE WITH blank, and do NOT select the ". matches newline" and click "REPLACE ALL". Yes I also love sed and awk but saying NPP cannot do this is just false.

                          – Collin Chaffin
                          Dec 30 '18 at 18:53



















                        • This may be an old answer but since it actually unbelievably has 2 votes (-1 now from me) wanted to comment on not only how wrong it is, but reiterate in a SINGLE command operation how I just (again) took a >100k line log file down to the 34 lines containing the one word (or phrase) in this case simply "error" in under 3 seconds by simply placing this regex in the FIND WHAT: ^(?!.*?error).*rn and leaving REPLACE WITH blank, and do NOT select the ". matches newline" and click "REPLACE ALL". Yes I also love sed and awk but saying NPP cannot do this is just false.

                          – Collin Chaffin
                          Dec 30 '18 at 18:53

















                        This may be an old answer but since it actually unbelievably has 2 votes (-1 now from me) wanted to comment on not only how wrong it is, but reiterate in a SINGLE command operation how I just (again) took a >100k line log file down to the 34 lines containing the one word (or phrase) in this case simply "error" in under 3 seconds by simply placing this regex in the FIND WHAT: ^(?!.*?error).*rn and leaving REPLACE WITH blank, and do NOT select the ". matches newline" and click "REPLACE ALL". Yes I also love sed and awk but saying NPP cannot do this is just false.

                        – Collin Chaffin
                        Dec 30 '18 at 18:53





                        This may be an old answer but since it actually unbelievably has 2 votes (-1 now from me) wanted to comment on not only how wrong it is, but reiterate in a SINGLE command operation how I just (again) took a >100k line log file down to the 34 lines containing the one word (or phrase) in this case simply "error" in under 3 seconds by simply placing this regex in the FIND WHAT: ^(?!.*?error).*rn and leaving REPLACE WITH blank, and do NOT select the ". matches newline" and click "REPLACE ALL". Yes I also love sed and awk but saying NPP cannot do this is just false.

                        – Collin Chaffin
                        Dec 30 '18 at 18:53











                        1














                        Better solution with regex replace:



                        (?!^.*SOMETEXT.*$)^.+r?n


                        And replace with nothing






                        share|improve this answer
























                        • Welcome to Super User! Care to explain this for those who might not know what each bit of the regex does? :)

                          – bertieb
                          May 1 '18 at 15:47
















                        1














                        Better solution with regex replace:



                        (?!^.*SOMETEXT.*$)^.+r?n


                        And replace with nothing






                        share|improve this answer
























                        • Welcome to Super User! Care to explain this for those who might not know what each bit of the regex does? :)

                          – bertieb
                          May 1 '18 at 15:47














                        1












                        1








                        1







                        Better solution with regex replace:



                        (?!^.*SOMETEXT.*$)^.+r?n


                        And replace with nothing






                        share|improve this answer













                        Better solution with regex replace:



                        (?!^.*SOMETEXT.*$)^.+r?n


                        And replace with nothing







                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered May 1 '18 at 14:37









                        LoneDevLoneDev

                        111




                        111













                        • Welcome to Super User! Care to explain this for those who might not know what each bit of the regex does? :)

                          – bertieb
                          May 1 '18 at 15:47



















                        • Welcome to Super User! Care to explain this for those who might not know what each bit of the regex does? :)

                          – bertieb
                          May 1 '18 at 15:47

















                        Welcome to Super User! Care to explain this for those who might not know what each bit of the regex does? :)

                        – bertieb
                        May 1 '18 at 15:47





                        Welcome to Super User! Care to explain this for those who might not know what each bit of the regex does? :)

                        – bertieb
                        May 1 '18 at 15:47











                        0














                        Use Search->Replace and enter a regular expression like ^[^ ].* and replace all with an empty string using Regular expression. Next step is to find empty lines searching for nn replacing with n using Extended multiple times until 0 occurrences were found. (use rnrn and rn depending on file format). If you have very many empty lines in a row, it is quickier to use nnnnnnn or even more n:s in the search string.






                        share|improve this answer




























                          0














                          Use Search->Replace and enter a regular expression like ^[^ ].* and replace all with an empty string using Regular expression. Next step is to find empty lines searching for nn replacing with n using Extended multiple times until 0 occurrences were found. (use rnrn and rn depending on file format). If you have very many empty lines in a row, it is quickier to use nnnnnnn or even more n:s in the search string.






                          share|improve this answer


























                            0












                            0








                            0







                            Use Search->Replace and enter a regular expression like ^[^ ].* and replace all with an empty string using Regular expression. Next step is to find empty lines searching for nn replacing with n using Extended multiple times until 0 occurrences were found. (use rnrn and rn depending on file format). If you have very many empty lines in a row, it is quickier to use nnnnnnn or even more n:s in the search string.






                            share|improve this answer













                            Use Search->Replace and enter a regular expression like ^[^ ].* and replace all with an empty string using Regular expression. Next step is to find empty lines searching for nn replacing with n using Extended multiple times until 0 occurrences were found. (use rnrn and rn depending on file format). If you have very many empty lines in a row, it is quickier to use nnnnnnn or even more n:s in the search string.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered May 29 '11 at 15:16









                            AndersTornkvistAndersTornkvist

                            1315




                            1315






























                                draft saved

                                draft discarded




















































                                Thanks for contributing an answer to Super User!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f290247%2fdelete-all-lines-in-notepad-except-lines-containing-a-word-i-need%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                Mouse cursor on multiple screens with different PPI

                                Agildo Ribeiro

                                Sometime when accessing a menu: “Ubuntu 16.04 has experienced an internal error”