Community
    • Login

    Help - Remove a line from a specific text but keep a part of the text

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    10 Posts 3 Posters 2.0k 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.
    • D
      Daniel Daniel
      last edited by

      Hello community, help me to delete a specific line from a text but I want to keep a part of the text.

      Example:

      xxxxxxxxxx | dddddddddd = [aaaaaaaaaa, ssssssssss]
      xxxxxxxxxx | dddddddddd = [aaaaaaaaaa, ssssssssss]
      xxxxxxxxxx | dddddddddd = [aaaaaaaaaa, ssssssssss]
      xxxxxxxxxx | dddddddddd = [aaaaaaaaaa, ssssssssss]

      I want to delete this pattern | dddddddddd = [aaaaaaaaaa, ssssssssss]
      and keep the xxxxxxxxxx text.

      Thanks.

      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @Daniel Daniel
        last edited by

        @Daniel-Daniel

        • FIND = | dddddddddd = [aaaaaaaaaa, ssssssssss]
        • REPLACE = empty
        • Search Mode = Normal
        • REPLACE ALL

        If that’s not sufficient, you will have to describe your problem more accurately. The advice below will help you ask a better question.

        ----

        Do you want regex search/replace help? Then please be patient and polite, show some effort, and be willing to learn; answer questions and requests for clarification that are made of you. All example text should be marked as literal text using the </> toolbar button or manual Markdown syntax. To make regex in red (and so they keep their special characters like *), use backticks, like `^.*?blah.*?\z`. Screenshots can be pasted from the clipboard to your post using Ctrl+V to show graphical items, but any text should be included as literal text in your post so we can easily copy/paste your data. Show the data you have and the text you want to get from that data; include examples of things that should match and be transformed, and things that don’t match and should be left alone; show edge cases and make sure you examples are as varied as your real data. Show the regex you already tried, and why you thought it should work; tell us what’s wrong with what you do get. Read the official NPP Searching / Regex docs and the forum’s Regular Expression FAQ. If you follow these guidelines, you’re much more likely to get helpful replies that solve your problem in the shortest number of tries.

        D 1 Reply Last reply Reply Quote 1
        • D
          Daniel Daniel @PeterJones
          last edited by

          @PeterJones Thanks, it works.

          But the last value ssssssssss are different in all lines, how I remove them but keep the xxxxxxxxxx value?

          PeterJonesP 1 Reply Last reply Reply Quote 0
          • PeterJonesP
            PeterJones @Daniel Daniel
            last edited by

            @Daniel-Daniel said in Help - Remove a line from a specific text but keep a part of the text:

            But the last value ssssssssss are different in all lines, how I remove them but keep the xxxxxxxxxx value?

            You can use search mode = regular expression (aka, regex) instead of normal mode.

            In regex mode, the [ and ] and | characters have special meanings, so you need to escape them.

            But you don’t tell us any rules, and didn’t follow the advice of giving examples that should and shouldn’t match – ie, you ignored all of my advice above. So once again, you’re leaving us to guess what you want, which won’t likely get you to your solution very quickly.

            But here’s a second guess as to what you want, and a solution that works for that guess: change the FIND to \| dddddddddd = \[aaaaaaaaaa, .*?\] and the Search Mode to Regular Expression (and make sure “. matches newline” is off) – this will delete from the | onward , allowing anything but a newline to come after the comma and before the ] … If you really meant that the dddddddddd, aaaaaaaaaa, and ssssssssss can all be different, then just replace the others with .*? as well… but at some point, it will probably be more generic than you intended.

            If this second guess doesn’t work for you, you will have to follow the advice you’ve already been given before I can do anything more to help.

            D 1 Reply Last reply Reply Quote 0
            • D
              Daniel Daniel @PeterJones
              last edited by

              @PeterJones Thanks for your help.

              Alejandro Perez | Age = [20] | Sex = [Male] | Phone number = 3009876543
              Carlos Gomez | Age = [20] | Sex = [Male] | Phone number = 3103457629

              I want to keep just the names, Alejandro Perez, Carlos Gomez, etc

              And delete all the additional information | Age = [20] | Sex = [Male] | Phone number = 3009876543 as you can see, the phone number are variable.

              PeterJonesP 1 Reply Last reply Reply Quote 1
              • PeterJonesP
                PeterJones @Daniel Daniel
                last edited by PeterJones

                @Daniel-Daniel ,

                Even easier:

                • FIND = \|.*$
                • REPLACE = empty
                • MODE = regular expression
                • REPLACE ALL

                If you had just said in the first place “I want to delete everything after the first | on any line (delete the | too)”, we would have gotten there a lot quicker.

                D 1 Reply Last reply Reply Quote 3
                • D
                  Daniel Daniel @PeterJones
                  last edited by

                  @PeterJones Thanks, it works.

                  L ML 1 Reply Last reply Reply Quote 1
                  • L ML
                    L M @Daniel Daniel
                    last edited by L M

                    @Daniel-Daniel

                    Hi,

                    I need to keep a group while moving it to the line above.

                    I have this:

                    WELLER,
                    IV, 3.

                    I need this:

                    WELLER, IV, 3.

                    I tried this without success:

                    Find: \r\n(\sIV,)
                    Replace: ($0)

                    PeterJonesP 1 Reply Last reply Reply Quote 0
                    • PeterJonesP
                      PeterJones @L M
                      last edited by

                      @L-M said in Help - Remove a line from a specific text but keep a part of the text:

                      Replace: ($0)

                      $0 is the whole match. You should have used $1 if you wanted just the contents of group #1 from your match.

                      L ML 1 Reply Last reply Reply Quote 0
                      • L ML
                        L M @PeterJones
                        last edited by L M

                        @PeterJones Thanks it’s working now.

                        I also figured out some occurences had only the CR from this answer:
                        https://community.notepad-plus-plus.org/post/17010

                        And could modify as this to accomodate:
                        Find: \r(\sIV,)
                        Replace: ($1)

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