TABLE OF CONTENTS
::pwtk::egrep_field
SYNOPSIS
proc ::pwtk::egrep_field {pattern file which_field {index ""}} {
PURPOSE
A more precise version of ::pwtk::egrep command. It returns only a specified field from the lines that matches the pattern.
ARGUMENTS
- pattern -- pattern to grep for [pattern matching is that of Tcl's "regexp" command]
- file -- file to grep
- which_field -- number of field from the grepped line to return; its meaning/syntax is the same as for Tcl's lindex command; 0 = first match; end = last match
- index -- [optional] which match to return; its meaning/syntax is the same as for Tcl's lindex command; 0 = first match; end = last match
SOURCE
set result "" pwtk::lineread line $file { if { [regexp $pattern $line] } { lappend result [lindex $line $which_field] } } if { $index != "" } { set result [lindex $result $index] } return $result }