Community
    • Login

    Batch deleting or replacing based on line numbers in multiple files

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    batch removedeleting linesreplacing
    3 Posts 2 Posters 1.1k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • G
      Golden000
      last edited by Golden000

      Cutting right to an example:-

      Line No. 1 (start of text files)
      Line No. 2
      Line No. 3
      Line No. 4
      ...
      Line No. 68
      Line No. 69
      ...
      Line No. 77
      ....
      Line No. 80 (end of text files)
      

      These lines numbers are shown on the right hand side of Notepad++. Contents of every lines may not be exactly the same across multiple files. The end of text files doesn’t necessarily ends at line no. 80. It could be more or less across these multiple files.

      Case 1: In this occasion I want to delete lines no. 68 to 77 in multiple files, regardless of their contents, empty or not (as these contents may vary accross multiple files).

      Case 2: I want to replace say, line no. 3 to 5 (again, the contents in these lines may not be the same) with 3 new lines of fixed contents like, for example:

      New Line 3: awefew
      New Line 4: gfwaef
      New Line 5: wefe

      Are they possible to achieve in Notepad++?
      If not, I am open to other suggestions.

      1 Reply Last reply Reply Quote 0
      • G
        Golden000
        last edited by

        @golden000 said in Batch deleting or replacing based on line numbers in multiple files:

        right hand side of Notepad++

        My bad, it’s left hand side of notepad++
        I dont know why I typed it wrong

        Neil SchipperN 1 Reply Last reply Reply Quote 0
        • Neil SchipperN
          Neil Schipper @Golden000
          last edited by Neil Schipper

          @golden000

          The transformations are:

          (skip 3 lines and) delete line 4
          F: \A(^.*\R){3}\K^.*\R
          R: (empty)
          
          (skip 1st 67 lines and) delete lines 68-77
          F: \A(^.*\R){67}\K(^.*\R){10}
          R: (empty)
          
          (skip 4 lines and) replace line 5
          F: \A(^.*\R){4}\K^.*
          R: This is the replacement for the removed line
          
          

          Modify the {numbers} to fit your needs.

          To see how they work on the active tab, in each case, bring up the Replace dialog (Ctl-h) and set Search Mode to Reg expr, leaving the box to its right unchecked. Fill in the Find & Replace texts. With (empty) ensure there are no invisible spaces. In each case even though you maybe doing a single F&R you must use ‘Replace All’ and not ‘Replace’ (a requirement imposed by use of \K).

          Although I haven’t tested it, they should also be fine using Find in Files (or Projects). Observe good backup practices.

          If you want actual batching, so that one big operation performs all transformations in one go, you’d need a scipting language solution (that drives a sequence of regex actions from a list). Probably someone else will have a concrete suggestion.

          1 Reply Last reply Reply Quote 2
          • First post
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors