Replacing new line sign ("\n") when the line after starts with ";"
-
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 -
Please show a sample of your data; best to follow the instructions HERE for this type of question.
-
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 " ".
-
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-styleCR
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
- FIND =
-
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:
Unfortunately, there is 10k+ of such lines within 600k+ lines file.
-
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.
- FIND =
-
@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!