#!/usr/local/bin/e ## # The find function from the E Tutorial, modified to show the # pathname. # Prints all lines of a given file that contains a given substring. # define find(file, substring) { for num => line in file { if (line indexOf(substring) != -1) { print(file getPath + ":" + num + ":" + line) } } } ## # The findall function from the E Tutorial, modified to take an # extension parameter. # Recursively walks a directory tree, and prints all lines in .txt # files that contain the given substring. # define findall(dirfile, ext, substring) { if (dirfile isDirectory) { for file in dirfile { findall(file, ext, substring) } } else if (dirfile getName endsWith(ext)) { find(dirfile, substring) } } define args := interp getArgs if (args size != 3) { throw("usage: findall.e rootname extension substring") } define root := file: (args[0]) findall(root, args[1], args[2])