Help duplicate files
-
@Adriano said in Help duplicate files:
@mkupper Select the part of the text with the following expression
[0-9]+.;([0-9]+(/[0-9]+)+)
Now I just need to compare, which is the part I don’t know.I am confused about why you have a dot. Your regex starts out with
[0-9]+.;which will match one or more numeric digits followed by any character followed by a semicolon. In the example data you have provided so far I only see numeric digits immediately followed by a semicolon meaning[0-9]+;will work unless there is something about your data you are not showing to us.Is the
17/05/2023part in the data a date in dd/mm/yyyy format? If so, then your;([0-9]+(/[0-9]+)+)regex expression would match many things that are not dates. That is dangerous as you may accidentally match something you did not intend to match. Examples of non-dates that are matched by your expression are:;12345/12345 ;12345/12345/12345 ;12345/12345/12345/12345/12345 ;0/0 ;0/0/0 ;0/0/0/0 ;0/0/0/0/0Is this intentional or do you want to match just dd/mm/yyyy format dates? I am going to assume that you only have dates and so if this was my data I would use
;[0-3][0-9]/[01][0-9]/20[0-9][0-9]It’s not perfect but is short and easy for humans to see what is happening.Thus, I would change the regex that locates the data to be
(;[0-9]+;[0-3][0-9]/[01][0-9]/20[0-9][0-9])I added a;at the front to make it less likely to accidentally match something in the data that you did not intend to match.To handle the “Now I just need to compare, which is the part I don’t know” part of the question the rexexp becomes:
Search for:
^(.+(;[0-9]+;[0-3][0-9]/[01][0-9]/20[0-9][0-9]) .+\R)(.+\2.+\R)+
Replace with\1That will find consecutive lines that contain the same pattern we are interested in and removes all of the duplicate lines.
Earlier I had suggested breaking the problem down into easier to understand parts. We can allow for non-consecutive lines but the expression becomes harder to understand.
Search for:
^(.+(;[0-9]+;[0-3][0-9]/[01][0-9]/20[0-9][0-9]) .+\R)(.+\R)*?(.+\2.+\R)+
Replace with\1\3Repeat that over and over until it stops finding matches There are four main groups:
\1 or
^(.+(;[0-9]+;[0-3][0-9]/[01][0-9]/20[0-9][0-9]) .+\R)is the entire first line of data where some later line also has the same data we are interested in/\2 or
(;[0-9]+;[0-3][0-9]/[01][0-9]/20[0-9][0-9])is inside \1 and both matches and captures the data pattern we are interested in.\3 or
(.+\R)*?matches zero or more lines of data. The?at the end makes this a non-greedy match meaning it will stop as soon as we hit part \4.\4 or
(.+\2.+\R)+is the part that matches a line that contains the \2 pattern we are interested in. The+at the end is optional and allows us to match consecutive lines that contain the \2 pattern we are interested in.The replacement of
\1\3gives us the first line with the data pattern and the possibly empty list of lines that don’t contain the data pattern. We discard \4 which are the lines that contain duplicates of the \2 pattern.While it works for testing this will fail in strange ways if your data contains thousands of lines. The
\3capturing group can’t handle more than a few thousand lines. It’s an issue with the regular expression engine. That’s part of why I suggested earlier to sort the data and then re-sorting. -
@mkupper You are absolutely right my regex is not very reliable, instead the one you created (^(.+(;[0-9]+;[0-3][0-9]/[01][0-9]/20[0-9][0-9][0-9]) .+R)(.+2.+R)+) works very well with the repeated consecutives now I only have to manually make the non consecutives, thank you very much for all the help.
-
This post is deleted! -
@Adriano said in Help duplicate files:
@mkupper You are absolutely right my regex is not very reliable, instead the one you created (^(.+(;[0-9]+;[0-3][0-9]/[01][0-9]/20[0-9][0-9][0-9]) .+R)(.+2.+R)+) works very well with the repeated consecutives now I only have to manually make the non consecutives, thank you very much for all the help.
@Adriano - You can use
^(.+(;[0-9]+;[0-3][0-9]/[01][0-9]/20[0-9][0-9]) .+\R)((?:.+\R)*?)(.+\2.+\R)+to safely search for non consecutives.While it is safe for searching for non consecutives the \3 group will get truncated if there are too many non-matching lines between the one with the pattern we are interested in and the lines that match the pattern. That’s why it’s not safe for search/replace using \1\3.
Also, I spotted an error in my earlier post. I had
(.+\R)*?for \3. That should be((?:.+\R)*?)The first version would only capture the first line of non-matching stuff though it skips all of them. Wrapping it in()captures all of the lines skipped though it will still truncate the data if the \3 group is too large. If your data has blank lines then use((?:.*\R)*?)to skip over and capture them.I did a quick test and it fails with “invalid regular expression” if somewhere over 45000 non consecutives lines is skipped. Thus it should be safe to use if your files contain less than 45000 lines. I did not try nailing down the exact count but know it fails at 50000 lines.
-
Hello, @adriano and All,
Here is a definitive method to get ALL unique lines and ONLY ONE of each duplicate lines of your file, whatever its size ( even
1,000,000lines ! ) in their original order !This method will involve some regex operations. For each of them :
-
Open the Replace (
Ctrl + H) -
Untick all box options
-
Type in the SEARCH and REPLACE regexes
-
Tick the
Wrap aroundoption -
Select the
Regular expressionsearch mode -
Click once only on the
Replace Allbutton
So, let’s start with this INPUT text :
;30-00000000-9;86;0;0;0;1;230178;17/05/2023 12:00;1;1;S72.3;1; ;30-00000000-9;10;0;0;0;1;347211;17/05/2023 12:00;1;1;S72.3;1; ;30-00000000-9;705;0;0;0;1;420302;17/05/2023 12:00;1;1;S72.3;1; ;30-00000000-9;86;0;0;0;1;230178;17/05/2023 12:00;1;1;S72.3;1; ;30-00000000-9;705;0;0;0;1;420302;17/05/2023 12:00;1;1;S72.3;1; ;30-00000000-9;11175;0;0;0;1;347211;17/05/2023 12:00;1;1;S72.3;1; ;30-00000000-9;86;0;0;0;1;230133;17/05/2023 12:00;1;1;S72.3;1; ;30-00000000-9;9072;0;0;0;1;420302;17/05/2023 12:00;1;1;S72.3;1; ;30-00000000-9;10;0;0;0;1;347211;17/05/2023 12:00;1;1;S72.3;1; ;30-00000000-9;86;0;0;0;1;230178;17/05/2023 12:00;1;1;S72.3;1; ;30-00000000-9;86;0;0;0;1;230178;17/05/2023 12:00;1;1;S72.3;1;-
First, we identify, with the Mark dialog (
Ctrl + M) the concerned zone to discriminate the duplicates, which is all the7thfield + the date of the8thfield, with the regex :- MARK
(?-s)^(?:;[^;\r\n]+){6};\K[^;\r\n]+;\d\d/\d\d/\d{4}
- MARK
-
Now, we add this concerned zone, at beginning of each line + one
Tabulationcharacter :-
SEARCH
(?-s)^(?:;[^;\r\n]+){6};([^;\r\n]+;\d\d/\d\d/\d{4}).+\R -
REPLACE
\1\t$0
-
230178;17/05/2023 ;30-00000000-9;86;0;0;0;1;230178;17/05/2023 12:00;1;1;S72.3;1; 347211;17/05/2023 ;30-00000000-9;10;0;0;0;1;347211;17/05/2023 12:00;1;1;S72.3;1; 420302;17/05/2023 ;30-00000000-9;705;0;0;0;1;420302;17/05/2023 12:00;1;1;S72.3;1; 230178;17/05/2023 ;30-00000000-9;86;0;0;0;1;230178;17/05/2023 12:00;1;1;S72.3;1; 420302;17/05/2023 ;30-00000000-9;705;0;0;0;1;420302;17/05/2023 12:00;1;1;S72.3;1; 347211;17/05/2023 ;30-00000000-9;11175;0;0;0;1;347211;17/05/2023 12:00;1;1;S72.3;1; 230133;17/05/2023 ;30-00000000-9;86;0;0;0;1;230133;17/05/2023 12:00;1;1;S72.3;1; 420302;17/05/2023 ;30-00000000-9;9072;0;0;0;1;420302;17/05/2023 12:00;1;1;S72.3;1; 347211;17/05/2023 ;30-00000000-9;10;0;0;0;1;347211;17/05/2023 12:00;1;1;S72.3;1; 230178;17/05/2023 ;30-00000000-9;86;0;0;0;1;230178;17/05/2023 12:00;1;1;S72.3;1; 230178;17/05/2023 ;30-00000000-9;86;0;0;0;1;230178;17/05/2023 12:00;1;1;S72.3;1;-
Then, add, at least,
20space characters at the end of the first line -
Run the
Edit > Column Editor...option (Alt + C)-
Choose the
Number to Insertoption -
Type in the value
1for theInitial Number,Increase byandRepeatoptions -
Use the default
spaceoption asLeadingchars as well as theDecoption -
Click on the
OKbuton -
Remove any unnecessary numbering at the very end of the file
-
In order to get this text :
230178;17/05/2023 ;30-00000000-9;86;0;0;0;1;230178;17/05/2023 12:00;1;1;S72.3;1; 01 347211;17/05/2023 ;30-00000000-9;10;0;0;0;1;347211;17/05/2023 12:00;1;1;S72.3;1; 02 420302;17/05/2023 ;30-00000000-9;705;0;0;0;1;420302;17/05/2023 12:00;1;1;S72.3;1; 03 230178;17/05/2023 ;30-00000000-9;86;0;0;0;1;230178;17/05/2023 12:00;1;1;S72.3;1; 04 420302;17/05/2023 ;30-00000000-9;705;0;0;0;1;420302;17/05/2023 12:00;1;1;S72.3;1; 05 347211;17/05/2023 ;30-00000000-9;11175;0;0;0;1;347211;17/05/2023 12:00;1;1;S72.3;1; 06 230133;17/05/2023 ;30-00000000-9;86;0;0;0;1;230133;17/05/2023 12:00;1;1;S72.3;1; 07 420302;17/05/2023 ;30-00000000-9;9072;0;0;0;1;420302;17/05/2023 12:00;1;1;S72.3;1; 08 347211;17/05/2023 ;30-00000000-9;10;0;0;0;1;347211;17/05/2023 12:00;1;1;S72.3;1; 09 230178;17/05/2023 ;30-00000000-9;86;0;0;0;1;230178;17/05/2023 12:00;1;1;S72.3;1; 10 230178;17/05/2023 ;30-00000000-9;86;0;0;0;1;230178;17/05/2023 12:00;1;1;S72.3;1; 11- Without any selection, run the
Edit > Line Operations > Sort Lines Lexicographically Ascendingoption :
We get the following sorted text :
230133;17/05/2023 ;30-00000000-9;86;0;0;0;1;230133;17/05/2023 12:00;1;1;S72.3;1; 07 230178;17/05/2023 ;30-00000000-9;86;0;0;0;1;230178;17/05/2023 12:00;1;1;S72.3;1; 01 230178;17/05/2023 ;30-00000000-9;86;0;0;0;1;230178;17/05/2023 12:00;1;1;S72.3;1; 04 230178;17/05/2023 ;30-00000000-9;86;0;0;0;1;230178;17/05/2023 12:00;1;1;S72.3;1; 10 230178;17/05/2023 ;30-00000000-9;86;0;0;0;1;230178;17/05/2023 12:00;1;1;S72.3;1; 11 347211;17/05/2023 ;30-00000000-9;10;0;0;0;1;347211;17/05/2023 12:00;1;1;S72.3;1; 02 347211;17/05/2023 ;30-00000000-9;10;0;0;0;1;347211;17/05/2023 12:00;1;1;S72.3;1; 09 347211;17/05/2023 ;30-00000000-9;11175;0;0;0;1;347211;17/05/2023 12:00;1;1;S72.3;1; 06 420302;17/05/2023 ;30-00000000-9;705;0;0;0;1;420302;17/05/2023 12:00;1;1;S72.3;1; 03 420302;17/05/2023 ;30-00000000-9;705;0;0;0;1;420302;17/05/2023 12:00;1;1;S72.3;1; 05 420302;17/05/2023 ;30-00000000-9;9072;0;0;0;1;420302;17/05/2023 12:00;1;1;S72.3;1; 08-
Now, let’s remove all the NON-desired duplicate lines with the following regex S/R :
-
SEARCH
(?-s)^(.+?)\t.+\R\K(\1\t.+\R)+ -
REPLACE
Leave EMPTY
-
Consequently, your text is reduced to :
230133;17/05/2023 ;30-00000000-9;86;0;0;0;1;230133;17/05/2023 12:00;1;1;S72.3;1; 07 230178;17/05/2023 ;30-00000000-9;86;0;0;0;1;230178;17/05/2023 12:00;1;1;S72.3;1; 01 347211;17/05/2023 ;30-00000000-9;10;0;0;0;1;347211;17/05/2023 12:00;1;1;S72.3;1; 02 420302;17/05/2023 ;30-00000000-9;705;0;0;0;1;420302;17/05/2023 12:00;1;1;S72.3;1; 03-
Now, place the caret at column
102of the first line of your text : -
Perform a zero-length column-mode selection of all the lines, at column
102 -
Run the
Edit > Line Operations > Sort Lines Lexicographically Ascendingoption, onto this zero-length selection :
We get the new text below :
230178;17/05/2023 ;30-00000000-9;86;0;0;0;1;230178;17/05/2023 12:00;1;1;S72.3;1; 01 347211;17/05/2023 ;30-00000000-9;10;0;0;0;1;347211;17/05/2023 12:00;1;1;S72.3;1; 02 420302;17/05/2023 ;30-00000000-9;705;0;0;0;1;420302;17/05/2023 12:00;1;1;S72.3;1; 03 230133;17/05/2023 ;30-00000000-9;86;0;0;0;1;230133;17/05/2023 12:00;1;1;S72.3;1; 07Remark : Due to this fix in Notepad++
v8.0[ 32. Fix sort with column key selection that appears after tab characters. (Fix #9682) ] , I use a column mode selection as column102( instead of the logical value103) just in case that you execute all this method on a N++ version prior to the8.0one !-
Finally, with this last regex S/R, we get rid of the leading zone as well as the ending zone of numbers :
-
SEARCH
^(.+?)\t|\x20+\d+$ -
REPLACE
Leave EMPTY
-
And here is your expected OUTPUT test :
;30-00000000-9;86;0;0;0;1;230178;17/05/2023 12:00;1;1;S72.3;1; ;30-00000000-9;10;0;0;0;1;347211;17/05/2023 12:00;1;1;S72.3;1; ;30-00000000-9;705;0;0;0;1;420302;17/05/2023 12:00;1;1;S72.3;1; ;30-00000000-9;86;0;0;0;1;230133;17/05/2023 12:00;1;1;S72.3;1;
Reminder : This method should work correctly, even with huge files !
Best Regards,
guy038
-
-
@guy038 Hi Guy038. I looked at your solution and one step is not clear to me: why do you mark the relevant columns (“concerned zone”) before you copy them to the front of the lines?
-
Hi, @adriano,
I’ve just remarked your post where you add a real INPUT file ! So, if we placed the concerned part, between the
REL_PandDIA_boundaries, below, in a new tab :;30-10000010-9;705;0;0;0;1;420302;17/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;230178;17/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;11175;0;0;0;1;347211;17/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;230133;17/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770772;17/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;17/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770192;17/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770902;17/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770412;17/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;705;0;0;0;1;177141;17/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770171;17/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770546;17/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;10;0;0;0;1;347211;17/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;18/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;19/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;20/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;10;0;0;0;1;770192;21/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;10;0;0;0;1;770902;21/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;10;0;0;0;1;770546;21/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;10;0;0;0;1;770412;21/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;10;0;0;0;1;230178;21/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;21/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;10;0;0;0;1;230133;21/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;10;0;0;0;1;770711;21/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;22/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;23/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770902;24/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770412;24/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770546;24/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;230178;24/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770711;24/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770192;24/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;24/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;230133;24/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;25/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;26/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;27/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;28/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;10;0;0;0;1;121012;29/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;10;0;0;0;1;170175;29/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;10;0;0;0;1;347211;29/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;121012;29/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;29/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;11175;0;0;0;1;347211;29/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;4066;0;0;0;1;121012;29/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;230133;30/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;230178;30/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770192;30/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770412;30/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770546;30/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770711;30/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770902;30/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;30/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;31/05/2023 12:00;1;1;S72.3;1;After all the process, we finally get the following OUTPUT text :
;30-10000010-9;705;0;0;0;1;420302;17/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;230178;17/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;230133;17/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770772;17/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770192;17/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770902;17/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770412;17/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;705;0;0;0;1;177141;17/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770171;17/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770546;17/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;10;0;0;0;1;347211;17/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;18/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;19/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;20/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;10;0;0;0;1;770192;21/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;10;0;0;0;1;770902;21/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;10;0;0;0;1;770546;21/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;10;0;0;0;1;770412;21/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;10;0;0;0;1;230178;21/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;21/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;10;0;0;0;1;230133;21/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;10;0;0;0;1;770711;21/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;22/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;23/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770902;24/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770412;24/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770546;24/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;230178;24/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770711;24/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770192;24/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;24/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;230133;24/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;25/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;26/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;27/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;28/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;10;0;0;0;1;121012;29/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;10;0;0;0;1;170175;29/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;10;0;0;0;1;347211;29/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;29/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;230133;30/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;230178;30/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770192;30/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770412;30/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770546;30/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770711;30/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770902;30/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;30/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;31/05/2023 12:00;1;1;S72.3;1;
5duplicate lines have been deleted from the initial textBR
guy038
-
Hello, @paul-wormer and All,
Well, it’s rather an implied operation which must be realized before creating the first regex S/R. I just wanted to point out that :
-
Firstly, we have to find out all the zones to be added, not specifically adjacent, which allow to discriminate the duplicates lines
-
Secondly, we must create the appropriate S/R to correctly insert this/these zone(s) at the beginning of each line, in a specific order ( I mean
\1\2\3\t$0or\2\3\1\t$0or … , in case of multi-zones )
Best Regards
guy038
-
-
@Adriano
@Paul-Wormer said in Help duplicate files:@wonkawilly Your solution, elegant as it is, changes the order of the lines. The solutions of @mkupper and @PeterJones are fairly complex exactly because they conserve the order.
Sorry, Paul you are right I did not even noticed that the csv query plugin sqllite engine execution changed the row order: I did not put the ORDER BY clause into the query and I gave for granted that without it rows order won’t change: I was wrong. Thank you for making me notice that. Here the same main approach with the necessary corrections, now should return the correct results:
-
First with Ctrl+Home goto the very first char of the very first row;

-
Then go to Menu > Column editor and add a progressive number to all rows



-
Open the Csv Query panel and write and execute the following query
SELECT * FROM THIS GROUP BY COL8, COL9 ORDER BY COL1-
The query will return the following results

-
Create new csv file using Right Mouse Button menu from CSV Query plugin window

-
And set the options you like from the next little dialog that the procedure will show
-
After the creation of the new csv, clean up the unwanted progressive number and other unwanted chars that in case might be present into the new csv file keeping the first “;”

-
This will be the clean result, and you are almost ready

-
Now delete from the original file the rows after the seventh (no screenshot for this step on)
-
Delete from the new file the first rows until you match the seventh (that is yet into the first file) should be first 5 rows to delete from the new csv
-
Copy the resulting rows still remaining from the new file and paste them into the old one.
The following should be the result:
;30-10000010-9;705;0;0;0;1;420302;17/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;230178;17/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;11175;0;0;0;1;347211;17/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;230133;17/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770772;17/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;17/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770192;17/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770902;17/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770412;17/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;705;0;0;0;1;177141;17/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770171;17/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770546;17/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;10;0;0;0;1;347211;17/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;18/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;19/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;20/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;10;0;0;0;1;770192;21/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;10;0;0;0;1;770902;21/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;10;0;0;0;1;770546;21/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;10;0;0;0;1;770412;21/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;10;0;0;0;1;230178;21/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;21/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;10;0;0;0;1;230133;21/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;10;0;0;0;1;770711;21/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;22/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;23/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770902;24/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770412;24/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770546;24/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;230178;24/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770711;24/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770192;24/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;24/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;230133;24/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;25/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;26/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;27/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;28/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;10;0;0;0;1;170175;29/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;29/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;11175;0;0;0;1;347211;29/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;4066;0;0;0;1;121012;29/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;230133;30/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;230178;30/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770192;30/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770412;30/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770546;30/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770711;30/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770902;30/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;30/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;31/05/2023 12:00;1;1;S72.3;1; -
-
Hi, @adriano, @wonkawilly, @paul-wormer and All,
I’m sorry, @wonkawilly, but it seems that your final OUTPUT text still contains
2duplicates lines, according to the @adriano’s logic !
The concerned lines, from your final text, are :
- Lines
1and6
;30-10000010-9;705;0;0;0;1;420302;17/05/2023 12:00;1;1;S72.3;1; discriminate zone = 420302;17/05/2023 12:00 ;30-10000010-9;9072;0;0;0;1;420302;17/05/2023 12:00;1;1;S72.3;1; discriminate zone = 420302;17/05/2023 12:00- Lines
3and13
;30-10000010-9;11175;0;0;0;1;347211;17/05/2023 12:00;1;1;S72.3;1; discriminate zone = 347211;17/05/2023 12:00 ;30-10000010-9;10;0;0;0;1;347211;17/05/2023 12:00;1;1;S72.3;1; discriminate zone = 347211;17/05/2023 12:00Best Regards,
guy038
P.S. :
In my solution, the duplicate lines
6and3are correctly deleted ! - Lines
-
You are right: it was my copy-paste mistake. I’m sorry for that. But please notice the original screenshots are actually correct, in fact in my answer are removed the lines 1 and 3 and in fact in screenshots are present the lines 2 and 4 but not 1 and 3:

Probably I might have screenshotted the right file but copy-pasted from the wrong one of those I was experimenting with. Sorry again.
So I suppose that both methods work well after all.
;30-10000010-9;86;0;0;0;1;230178;17/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;230133;17/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770772;17/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;17/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770192;17/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770902;17/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770412;17/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;705;0;0;0;1;177141;17/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770171;17/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770546;17/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;10;0;0;0;1;347211;17/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;18/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;19/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;20/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;10;0;0;0;1;770192;21/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;10;0;0;0;1;770902;21/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;10;0;0;0;1;770546;21/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;10;0;0;0;1;770412;21/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;10;0;0;0;1;230178;21/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;21/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;10;0;0;0;1;230133;21/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;10;0;0;0;1;770711;21/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;22/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;23/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770902;24/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770412;24/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770546;24/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;230178;24/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770711;24/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770192;24/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;24/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;230133;24/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;25/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;26/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;27/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;28/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;10;0;0;0;1;170175;29/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;29/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;11175;0;0;0;1;347211;29/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;4066;0;0;0;1;121012;29/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;230133;30/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;230178;30/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770192;30/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770412;30/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770546;30/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770711;30/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;86;0;0;0;1;770902;30/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;30/05/2023 12:00;1;1;S72.3;1; ;30-10000010-9;9072;0;0;0;1;420302;31/05/2023 12:00;1;1;S72.3;1; -
P Paul Wormer referenced this topic on