6.10.2 Grep

One external tool in the Tools menu is already predefined: a menu item to call the grep utility (”Tools—Grep” or Shift-F2). Grep searches for a given string in files and returns the lines which contain the string. The search string can even be a regular expression. For this menu item to work, the grep program must be installed, since it is not distributed with Free Pascal.

The messages window displayed in figure (6.17) in the previous section shows the output of a typical grep session. The messages window can be used in combination with grep to find special occurrences in the text.

Grep supports regular expressions. A regular expression is a string with special characters which describe a whole class of expressions. The command line in dos or linux has limited support for regular expressions: entering ls *.pas (or dir *.pas) to get a list of all Pascal files in a directory. *.pas is something similar to a regular expression. It uses a wildcard to describe a whole class of strings: those which end on ”.pas”. Regular expressions offer much more: for example [A-Z][0-9]+ describes all strings which begin with an upper case letter followed by one or more digits.

It is outside the scope of this manual to describe regular expressions in great detail. Users of a linux system can get more information on grep using man grep on the command line.