TABLE OF CONTENTS
::pwtk::grep
SYNOPSIS
proc ::pwtk::grep {pattern file {index ""}} {
PURPOSE
A simple grep command (but without options). Lines that matches the pattern are returned as the Tcl list. If index argument is specified only the index-th match (list element) is returned.
ARGUMENTS
- pattern -- pattern to grep for [pattern matching is that of Tcl's "string match" command]
- file -- file to grep
- index -- [optional] which match to return; its meaning/syntax is the same as for Tcl's lindex command; 1 = first match; end = last match
RETURN VALUE
- lines that matches the pattern in the form of Tcl list
- if 'index' argument is specified, only the index-th element of the resulting list is returned
SOURCE
set result "" pwtk::lineread line $file { if { [string match *$pattern* $line] } { lappend result $line } } if { $index != "" } { set result [lindex $result $index] } return $result }