GPS is editing! [GPS] May 28, 2002: Diff is a common tool used in Unix-like systems. It compares two (sometimes more) files and outputs the differences. I wrote a version that only tracks content changes after seeing some code done by Master Tcl'er [KBK]. Here is my version: ---- #!/bin/tclsh8.3 #Thanks to Kevin Kenny for showing me an example of how to do this. #This is all new code by George Peter Staplin. #It doesn't deal with \n differences on blank lines, only actual content changes and spaces. #The SECTION usage reminds me of COBOL, and should help if I write a patch program. proc diff {origList newList} { set result "SECTION lines-removed-from-new-file:\n" set origLine 1 foreach orig $origList { set didNotMatch 1 foreach new $newList { if {[string equal $orig $new]} { set didNotMatch 0 } } if {$didNotMatch} { set formattedLine [format "%-5d" $origLine] append result "$formattedLine < $orig\n" } incr origLine } append result "SECTION lines-added-to-new-file:\n" set newLine 1 foreach new $newList { set didNotMatch 1 foreach orig $origList { if {[string equal $orig $new]} { set didNotMatch 0 } } if {$didNotMatch} { set formattedLine [format "%-5d" $newLine] append result "$formattedLine > $new\n" } incr newLine } return $result } proc main {argc argv} { if {$argc != 2} { return -code error "please use 2 arguments when calling $::argv0" } set orig [lindex $argv 0] set new [lindex $argv 1] set fi [open $orig r] set data [read $fi] close $fi set origList [split $data \n] set fi [open $new r] set data [read $fi] close $fi set newList [split $data \n] puts [diff $origList $newList] } main $::argc $::argv ---- Example output: $ ./gps_diff_2.tcl diff1.test diff2.test SECTION lines-removed-from-new-file: 11 < regsub -all {\t} $data " " newData 12 < regsub -all {\n} $newData "\n " theData SECTION lines-added-to-new-file: 11 > regsub -all {\n} $data "\n " theData 15 > puts DONE ---- See also [diff in Tcl]