Hello i have tried to remove duplicates in a text file using TextFX plugin in notepad++ but it's didn't works for this type of text
209.116.247.120|admin|default|Taiwan (TW)|Tai-pei|Taipei|Unknown
209.116.247.120|admin|default|
209.116.49.130|admin|admin
209.116.49.130|admin|admin|China (CN)|Henan|Zhengzhou|Unknown
209.116.55.142|admin|admin
209.116.55.142|admin|admin|Korea, Republic of (KR)|Seoul-t'ukpyolsi|Seoul|Unknown
209.116.65.26|admin|admin
209.116.65.26|admin|admin|New Zealand (NZ)|Unknown|Unknown|Unknown
As you can see there's duplicates with added countries so i would like to remove these duplicates
209.116.247.120|admin|default|
209.116.49.130|admin|admin
209.116.55.142|admin|admin
209.116.65.26|admin|admin
or whether these duplicates
209.116.247.120|admin|default|Taiwan (TW)|Tai-pei|Taipei|Unknown
209.116.49.130|admin|admin|China (CN)|Henan|Zhengzhou|Unknown
209.116.55.142|admin|admin|Korea, Republic of (KR)|Seoul-t'ukpyolsi|Seoul|Unknown
209.116.65.26|admin|admin|New Zealand (NZ)|Unknown|Unknown|Unknown
If someone have any idea or regex command to fix this, I would appreciate it please And give commands for both thanks.
Answer
- Ctrl+H
- Find what:
^(([^|]+[|][^|]+[|][^|]+)[|]?.*)\R\2
- Replace with:
$1
- Replace all
Explanation:
^ : begining of line
( : start group 1
( : start group 2
[^|]+ : 1 or more NON pipe character |
[|] : a pipe
[^|]+ : 1 or more NON pipe character |
[|] : a pipe
[^|]+ : 1 or more NON pipe character |
) : end group 2
[|]? : a pipe, optional
.* : 0 or more any character but newline
) : end group 1
\R : any kind of line break
\2 : backreference to group 2
- DO NOT CHECK
. matches newline
Replacement:
$1 : content of group, the first dupplicate line
Result for given example:
209.116.247.120|admin|default|Taiwan (TW)|Tai-pei|Taipei|Unknown|
209.116.49.130|admin|admin|China (CN)|Henan|Zhengzhou|Unknown
209.116.55.142|admin|admin|Korea, Republic of (KR)|Seoul-t'ukpyolsi|Seoul|Unknown
209.116.65.26|admin|admin|New Zealand (NZ)|Unknown|Unknown|Unknown
No comments:
Post a Comment