TABLE OF CONTENTS
::pwtk::egrep
SYNOPSIS
proc ::pwtk::egrep {pattern file {index ""}} {
PURPOSE
A simple egrep 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 "regexp" command]
- file -- file to grep
- index -- [optional] which match to return; its meaning/syntax is the same as for Tcl's lindex command; 0 = 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 { [regexp $pattern $line] } { lappend result $line } } if { $index != "" } { set result [lindex $result $index] } return $result }