Saving searches

Very often, it is convenient to save the various searches that you run on coded corpora with so-called shell scripts.

When you type commands at the keyboard, you are giving commands to the shell one by one. When you run (a.k.a. execute) a shell script, you are giving the commands in the script to the shell in a batch.

I've put together two sample shell scripts for you to edit and tailor to your own purposes. The first one executes a batch of grep searches and outputs the results so that you can enter them into a spreadsheet program. The second one generates a file with results that you can import into a spreadsheet program directly. This obviates the need to type in the results, with its attendant risks of typos.

Sample shell script for executing a batch of grep commands

This shell script (batchGrep) illustrates how you can put together a list of searches that you want to perform, check them for typos, make sure that you're covering all the cases that you want to cover, remove and add searches, and so on.

Copy the script into your own account. If you want, you can make a separate directory to store this and other scripts. If so, you'll have to be in that directory to run the script, or you'll have to edit your .cshrc file to make it possible to run the script from other directories.


cp /htdocs/courses/Fall_2008/ling300/batchGrep .

You don't have to call your copy batchGrep. You could copy it and give it some different name, as illustrated below.


cp /htdocs/courses/Fall_2008/ling300/batchGrep myVeryOwnShellScript

Open the file in Emacs and get a sense of what it does.

emacs batchGrep

In order to run batchGrep, you'll have to turn it from an ordinary text file into an executable program (this is often called changing permissions on the file). To do this, close the file in Emacs. At the system prompt, type

chmod 755 batchGrep

You only need to use chmod once. Once the file is executable, it stays that way.

From now on, you can run the script by simply typing its name.

batchGrep

You can save the output of the shell script by "piping" it into a file. The file is an ordinary file that can be viewed with Emacs or more.

batchGrep > firstResults

Go back and forth between editing and running the script to learn how it works and to get it to do what you want.

Sample shell script for generating a spreadsheet

You can further expedite your work by writing a shell script that generates a file that can be directly imported into a spreadsheet program. You can access a sample of such a script by typing
cp /htdocs/courses/Fall_2008/ling300/spreadsheetGenerator .

Once again, you can review and edit the file with Emacs and run it once you've changed its permissions with chmod. As with the earlier script, you can save the output by "piping" it to a file. For instance:

spreadsheetGenerator > aLittleSpreadsheet

You can use Emacs to view this file, too. But mostly, you will transfer it from babel to your laptop, and then import the file into your spreadsheet program. The particular steps will differ from user to user, and we'll help you work out the details.