Navigation

    Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Regex Help Wanted - Delete all lines containing "STRING"

    Help wanted · · · – – – · · ·
    4
    7
    95
    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.
    • Gary Smith
      Gary Smith last edited by

      I have an output file created by program A that is then read by program B.

      Program A generates and appends each file with “System Tag ID-DD/MM/YYYY”, these files can be in batches of 10 -> 1000

      Program B does not appreciate this “erroneous” data so throws a wobbly when the file is imported.

      I have no control over the source code for either program so cannot either of them to play nice.

      Using N++, how would I go about using a regex to find each line containing the string “System Tag” then deleting that line in every open file?

      I’ve been googling and found a few methods but none of them seem to search past the first line or return the results needed, so im obviously missing something huge

      for example I found this on this community but adapting it fails to find any results (?i-s)^.MeX.\R (It is supposed to find each line containing MeX in any case and replace the line with BLANK when replace is used

      Thank guys

      Alan Kilborn 1 Reply Last reply Reply Quote 0
      • Alan Kilborn
        Alan Kilborn @Gary Smith last edited by

        @Gary-Smith

        how would I go about using a regex to find each line containing the string “System Tag” then deleting that line in every open file?

        Search for: (?-is)^.*?System Tag.*\R and replace with nothing.
        Use the Replace All in All Opened Documents button.

        Gary Smith 1 Reply Last reply Reply Quote 2
        • Phillip Stanhope
          Phillip Stanhope last edited by

          Can I suggest the “Sed” utility?
          sed “/Regex/d” InFile > OutFile
          “d” deletes the line containing the Regex.
          Alternatively : sed -i “/Regex/d” FileName - “-i” changes the <file> in place.
          Also : sed -i -r (extended Regex)
          I use a .bat that requests the Input and Output file names, copies the Input file to the Output file and then does lots of substitutions. However Sed then creates a temporary file “Sedxxx” for each command which then need deleting.
          If you have many files, you can create a DOS .bat file to process all files within a folder using the “FOR” command.
          WIndows 7, Sed for windows.

          Alan Kilborn 1 Reply Last reply Reply Quote 0
          • Alan Kilborn
            Alan Kilborn @Phillip Stanhope last edited by

            @Phillip-Stanhope said in Regex Help Wanted - Delete all lines containing "STRING":

            Can I suggest the “Sed” utility?

            You can, but really people are coming here looking for solutions to problems with the solutions involving Notepad++.

            Directing them to non-Notepad++ utilities, when there are ways to do what they are requesting within Notepad++, is considered bad form and off-topic.

            1 Reply Last reply Reply Quote 3
            • Gary Smith
              Gary Smith @Alan Kilborn last edited by

              @Alan-Kilborn Thanks for this alan, but think i’m missing something and just can’t get this to work. I have included a screenshot for the exact method im using and it still returns no results in the “replace” dialog box.

              Do you have any ideas where I could be going wrong?

              2021-08-27_15-00-07.jpg

              PeterJones 1 Reply Last reply Reply Quote 1
              • PeterJones
                PeterJones @Gary Smith last edited by PeterJones

                @Gary-Smith said in Regex Help Wanted - Delete all lines containing "STRING":

                Do you have any ideas where I could be going wrong?

                Your last line, which is the one that has System Tag on it, does not have a newline sequence, so \R has nothing to match. (?-is)^.*?System Tag.*(\R|\z) should work (see “Anchors” in the usermanual regex section)

                Gary Smith 1 Reply Last reply Reply Quote 1
                • Gary Smith
                  Gary Smith @PeterJones last edited by

                  @PeterJones said in Regex Help Wanted - Delete all lines containing "STRING":

                  (?-is)^.?System Tag.(\R|\z)

                  Worked flawlessly , thanks a lot folks for all your help, just saves me a whole bunch of work :)

                  1 Reply Last reply Reply Quote 1
                  • First post
                    Last post
                  Copyright © 2014 NodeBB Forums | Contributors