I am trying to use Unix's comm command to compare two files in Tcl.
I tried the below to no avail:
exec bash -c {comm -2 -3 <(sort file1) <(sort file2) > only_in_file1}
exec {comm -2 -3 <(sort file1) <(sort file2) > only_in_file1}
It is one of the quick way that I know to do so but if there is a method in Tcl, I would like to be introduced. In general, I would need to compare two files and find unique lines in only one of the files when the two files are lines of text of 10~100K lines.
Since your files are small by comparison with modern computer memories (and you're just looking for the lines in the first that aren't in the second), the simplest method of doing the filtering in pure Tcl is to hold the files in memory.
This isn't exactly the method used by
comm, but the logic it uses is more difficult to get right and requires both inputs to be sorted.