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

RETURN VALUE

SOURCE

    set result ""

    pwtk::lineread line $file {
        if { [string match *$pattern* $line] } {
            lappend result $line
        }
    }
    if { $index != "" } {
        set result [lindex $result $index]
    }

    return $result
}