• Login
Community
  • Login

Replacing new line sign ("\n") when the line after starts with ";"

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
7 Posts 3 Posters 44.4k 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.
  • P
    piotrtorchala
    last edited by Nov 21, 2023, 12:27 PM

    Hi,

    I have a 600k rows file, and I have to delete all the new line signs (“/n”) that are followed by a new line beginning with “;”.

    Is there anyone that can help with it?

    Best,
    Piotr

    A 1 Reply Last reply Nov 21, 2023, 12:30 PM Reply Quote 1
    • A
      Alan Kilborn @piotrtorchala
      last edited by Nov 21, 2023, 12:30 PM

      @piotrtorchala

      Please show a sample of your data; best to follow the instructions HERE for this type of question.

      1 Reply Last reply Reply Quote 0
      • P
        piotrtorchala
        last edited by PeterJones Nov 21, 2023, 1:54 PM Nov 21, 2023, 12:38 PM

        Here is the data sample:

        ;01;ABC;ABC/n
        ;01;A/n
        BC;ABC/n
        ;01;ABC;ABC/n
        
        

        And I have to replace “/n” by " " in all lines not beginning with “;”. In this example: to replace “/n” in row 2 by " ".

        P 1 Reply Last reply Nov 21, 2023, 2:04 PM Reply Quote 0
        • P
          PeterJones @piotrtorchala
          last edited by Nov 21, 2023, 2:04 PM

          @piotrtorchala,

          First, thanks for trying to put in into a text box in your second post. For future reference, the syntax is ``` , not ‘’’ – I used moderator power to change it for you this time. (If you have trouble remembering that, then just use the </> button on the toolbar to insert the two lines of that sequence to start and end your example text.)

          And now, on to your question:

          And I have to replace “/n” by " " in all lines not beginning with “;”. In this example: to replace “/n” in row 2 by " ".

          Your subject says Replacing new line sign ("\n") when the line after starts with ";" but your example text says /n . I believe you intended to say \n even in your example text.

          You are also not clear whether you have a literal backslash followed by a literal n before the actual newline character(s), or whether you were just trying to indicate that you have a newline sequence there.

          The other question becomes, do you really have just a unix-style LF (\n), or do you really have a Windows-style CR LF (\r\n) at the end of each line? Because it will change the results. (You can tell by View > Show Symbol… > Show End of Line, or just by looking near the lower-right of your Notepad++ status bar and see whether it says “Windows (CRLF)” or “Unix (LF)” down there.

          If the /n in your example text really means “I have a windows-style end-of-line sequence at the end of each line”, and you want to change any “end-of-line sequence followed by a semicolon” with just a space, then you could use

          • FIND = \r\n;
            REPLACE = \x20 (or type a space in the replacement box)
            SEARCH MODE = Regular Expression

          If you truly have just a unix-LF-style line ending, then instead use:

          • FIND = \n;
            REPLACE = \x20 (or type a space in the replacement box)
            SEARCH MODE = Regular Expression

          ----

          Useful References

          • Please Read Before Posting
          • Template for Search/Replace Questions
          • Formatting Forum Posts
          • Notepad++ Online User Manual: Searching/Regex
          • FAQ: Where to find other regular expressions (regex) documentation
          1 Reply Last reply Reply Quote 0
          • P
            piotrtorchala
            last edited by Nov 21, 2023, 2:57 PM

            Thank you @PeterJones for your support and all the tips.

            Answering your question:

            @PeterJones said in Replacing new line sign ("\n") when the line after starts with ";":

            or do you really have a Windows-style CR LF (\r\n)

            I have a Windows-style (CRLF).

            Unfortunately, the guidance given is not solving my issue, maybe a description of how I identified the lines that have to be merged with previous lines would be helpful, accompanied by a screenshot example.

            To identify all lines that I would like to delete the \n from the line before I used the following search expression:

            FIND = ^(?!;)

            Example on how it looks in the data base:

            N++.PNG

            Unfortunately, there is 10k+ of such lines within 600k+ lines file.

            P 1 Reply Last reply Nov 21, 2023, 3:57 PM Reply Quote 1
            • P
              PeterJones @piotrtorchala
              last edited by PeterJones Nov 21, 2023, 3:59 PM Nov 21, 2023, 3:57 PM

              @piotrtorchala ,

              FIND = ^(?!;)

              This is why it’s always a good idea when asking for help to share what you tried: I had misinterpreted your original statement that you wanted to replace the newlines before a semicolon at the start of the line. But it now that you showed that, I think that you really wanted to replace the newlines that don’t have a semicolon at the start of the next line.

              You actually had all the pieces that you needed: you just needed to replace the ; in mine with the (?!;) from yours, and it would have worked as you wanted (if I’m understanding)

              • FIND = \r\n(?!;)
                REPLACE = \x20 (or type a space in the replacement box)
                SEARCH MODE = Regular Expression

              If this still isn’t right, you will need to show both “before” and “after” data.

              1 Reply Last reply Reply Quote 1
              • P
                piotrtorchala
                last edited by Nov 21, 2023, 4:34 PM

                @PeterJones it is absolutely it, it works perfectly! Thank you so much!

                I’m a little bit embarrassed that I haven’t connected the dots…

                Thanks once again!

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