TABLE OF CONTENTS
::pwtk::egrep_field
SYNOPSIS
proc ::pwtk::egrep_field {pattern file which_field {index ""}} {
PURPOSE
A "field-segmented" 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 -- which field from the grepped line to return; its meaning/syntax is that of the Tcl 'lindex' command, i.e, 0 = first field; end = last field
- index -- [optional] which match to return; its meaning/syntax is the same as for the Tcl 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 }