You can have Stata scan a do-file instead of executing it, just as it would any text file. This is helpful if you have elaborate projects that cover entire directory trees full of little do-files that do different things for different subsets of the project if given conditions are met, and skip them otherwise. You don't want to go through these by hand if you just want to find the file where you used a certain command or operated on some variable you know.

In the example below I am going over 30 do-files, trying to figure out in which of them I operated on a variable called "foo". The client is a consortium of 30 local newspapers, and the do-files I am scanning are in separate folders, one for each local market. The list of markets is in a file I call ticker. This file keeps a timeline of source files that I receive weekly from each market. Some have started sending them earlier, some later. That part is not important now. For this project all I care about is that in the ticker file I can find a full listing of the markets, so I don't have to type them out. Here goes:

capture prog drop findString
prog def findString

local ratespath  "${root}rates/"
local tickerpath "${root}source/"
local searchfor  "foo"

drop _all
use "`tickerpath'ticker.dta"
levelsof market, local(markets)
local markets: list clean markets

foreach market in `markets' {
  local myfilein "`ratespath'`market'/rates_`market'.do"
  capture confirm file "`myfilein'"
  if _rc==0 {
    tempname fh_in
    file open `fh_in' using "`myfilein'", read
    local linenum=0
    file read `fh_in' line
    while r(eof)==0 {
      local linenum=`linenum'+1
      if regexm(`"`macval(line)'"',"`searchfor'") {
        di "`searchfor' found in rates_`market'.do on line `linenum'"
      file read `fh_in' line
    file close `fh_in'
    di "`searchfor' not found in rates_`market'.do"
  else {
    di "no rates_`market'.do file found for `market'"

The idea is simple. First I check if the do-file of interest -- rates_`market'.do -- even exists. If it does, I open it for reading line by line until I reach the end-of-file character, which in Stata translates to a non-zero value for the internal local r(eof). The first time I find "foo" I report that I found it, exit the reading loop, and move on to the next file. If I don't find it, I report that I didn't, and move on to the next file. 

There are a few niceties. Each line of of the file is read into a macro called simply `line'. But when I look for "foo", I'm not looking in `line'. Instead, I am looking in its raw version, `"`macval(line)'"'. This function (the name comes from "macro value") preserves all the content as it finds it. Normally, `line' alone might be tempted to skip things like quotation marks, special characters, etc. Observe the compound quotes. You will get used to them. And observe the regular expression-matching command regexm. You will grow very fond of it.