Forum Discussion
Ddib_147504
Nimbostratus
Mar 18, 2014How to remove duplicate lines in file with TCL
Hi Team,
I want to remove duplicate files in a txt file with TCL, i opened the file in r and w in the same time and i did two foreach, but with no result.
thank you
Ddib_147504
Nimbostratus
Mar 18, 2014i tested this code, but i dont know where is the probleme:
set in [open file.txt "r"]
array set seen {}
while {[gets $in line] != -1} {
blank lines should be printed as-is
if {[string length [string trim $line]] == 0} {
puts $line
continue
}
create the "key" for this line
regsub {\mPoint \d+} $line {} key
regsub {\mcolor=\w+} $key {} key
print the line only if the key is unique
if { ! [info exists seen($key)]} {
puts $line
set seen($key) true
}
}
close $in
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects