Community
    • Login

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

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    7 Posts 3 Posters 60.5k Views 2 Watching
    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 Offline
      piotrtorchala
      last edited by

      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

      Alan KilbornA 1 Reply Last reply Reply Quote 1
      • Alan KilbornA Offline
        Alan Kilborn @piotrtorchala
        last edited by

        @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 Offline
          piotrtorchala
          last edited by PeterJones

          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 " ".

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

            @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 Offline
              piotrtorchala
              last edited by

              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.

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

                @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 Offline
                  piotrtorchala
                  last edited by

                  @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

                  Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                  Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                  With your input, this post could be even better 💗

                  Register Login
                  • First post
                    Last post
                  The Community of users of the Notepad++ text editor.
                  Powered by NodeBB | Contributors