grep and diff

grep

grep is a UNIX command that allows you to search a file for a string or a so called regular expression. The syntax is the following:

grep [-e expression][filename]

If you type this then you will get the lines of the file that contain the given expression. This is very useful if you want to look for the defintion a certain variable, a typo or anything else you might want to search. The filename can be replaced by the "*" symbol, so the search will be performed on all the files in the current directory.

You can have several options for searching, such as "do not display filenames", "ignore case" and so on. These options can be specified in the command line.

grep is actually a member of a bigger function family, that contains the commands grep, egrep and fgrep.

To learn more about these functions, the way they are used, the possible options and the defintion of a regular expression, go to your troi account and type

man grep

at your prompt.

diff

diff is a UNIX command that displays line-by-line differences between pairs of text files. The syntax of the command is the following:

diff filename1 filename2

After typing this at your troi prompt, the computer will tell you what lines must be changed in the files to bring them into agreement.

This command is very useful if you want to see what were the last changes you made to a program, especially if your program doesn't run after these changes. So you can use diff to compare your file to the previous version of the file which was probably saved by emacs in file with the same name followed by ~.

To find out more about this command, as well as about some options you can use, go to your troi account and type

man diff

at the prompt.