open files in a directory and then find someword in the text tcl tk


cd /home/Desktop/Bl


set files [glob *]
set sofar 0

foreach f $files {
## start to read in the file name
  set sofar 0
  set fhandle [open [file join /home/Desktop/Bl/ $f] r]
  while {[gets $fhandle lyne] > -1} {
  incr sofar
  if {[regexp "files" $lyne ] >0 } {
   puts "The file $f has the keywords 'files' at line $sofar"
     }
   }
}

原文地址:https://www.cnblogs.com/greencolor/p/2031709.html