Hello, I need to remove duplicated lines in editor without resorting and leaving last duplicated row. I found a regular expression for notepad++, which works. But I have to modify expression for FAR and I don't know how.
The regular expression for search is: ^(.*?)$\s+?^(?=.*^\1$)
Replace expression is empty.
Thanks
KlepetoX wrote: ↑Tue 11 Oct, 2022 10:31
The regular expression for search is: ^(.*?)$\s+?^(?=.*^\1$)
AFAIK, FAR doesn't support multi-line regular expressions. Yet e.g. the RESearch plugin does, you can find its announcements in the Russian-language part of the forum.
KlepetoX, alternatively, you can use the Filters plugin to replace your editor text with the result of running gawk (newer version gets installed e.g. with Git for Windows) with the following script:
# Removes duplicated lines from stdin/files and outputs the unique ones to stdout in the original order.
# Distribution: Freeware, AS IS
#
# Version : 0.1
# Date : 2013-03-14
# Author : HaRT
# History :
# 200?-??-??: v.0.0: initial version (keep-first)
# 2013-03-14: v.0.1: added keep-last option; added ToDo 1-3
# 2013-03-18: : compatibility fix: "func" --> "function"
#
# Parameters : keep - which line instance to keep ("last"/...)
#
# ToDo :
# 1. support case-aware comparison
# 2. support diacritics-aware comparison
# 3. support normalization-aware comparison
# Which line instance to keep: true - the last, false - the first.
function keepLast() { return keep == "last" }
{
b = $0 in lines
if( b && keepLast() )
delete idxes[ lines[ $0 ] ]
if( ! b || keepLast() )
idxes[ lines[ $0 ] = ++ c ] = $0
}
END \
{
for( i = 1; i <= c; ++ i )
if( i in idxes )
print idxes[ i ]
}
like this: path\to\gawk.exe -f path\to\uniq.awk -v keep=last
Maybe I'll try it, but in the meantime I'll wait for Shmuel solution. I have also my bad own solution - read lines from text file to SQL table from end to beginning, then SELECT DISTINCT to a new table and write to text file back from the end to beginnig again. Complicated, working but not optimal solution outside of FAR.