When you type commands at the keyboard in the ordinary way, you are giving commands to the shell one by one. When you run (a.k.a. execute) a shell script, you give 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 script is intended to introduce you to shell scripts; it simply executes a batch of grep searches, outputting the results to the screen or to a file. In principle, you could type the results from a script like this one into a spreadsheet program by hand. Don't do this, though, because it is both time-consuming and error-prone. Instead, use a script of the second type, which generates output that is suitable for importing into a spreadsheet program directly.
# this script contains some sample searches on the coded PPHCE # pound signs at the very beginning of a line indicate comments # see what happens when you comment out lines # for instance, add a pound sign at the beginning of some of the "echo" lines # then see what happens when you uncomment those lines (remove the pound sign) echo "negative declaratives, ordinary verbs, old grammar, text from 1500-1519" grep -c "^V:.:.:.:.:.:.:.:.:.:5:[01]" ling300.cod.ooo echo "negative declaratives, ordinary verbs, new grammar, text from 1500-1519" grep -c "^v:.:.:.:.:.:.:.:.:.:5:[01]" ling300.cod.ooo # blank lines in the program don't generate blank lines in the output # if you need to generate a blank line, use the following line echo "" echo "questions, 'know' class, old grammar, author born 1680-1699" grep -c "^.:K:.:.:.:.:.:6:[89]" ling300.cod.ooo echo "questions, 'know' class, old grammar, author born 1680-1699" grep -c "^.:k:.:.:.:.:.:6:[89]" ling300.cod.ooo
chmod 755 batchGrep.sh
You only need to use chmod once. Once the file is executable, it stays that way.
If the above command gives you an error message, try one of the following two options.bash batchGrep.sh
./batchGrep.sh
batchGrep.sh
bash batchGrep.sh > firstResults
# this script generates a spreadsheet that is set up as indicated below # the script will fill in the cells marked by ___ # the script doesn't calculate the percentages; you will do that # after importing the output of the script into your spreadsheet program # . 1500-1519 1520-1539 1540-1559 # negative_declarative_ordinary_verb_old ___ ___ ___ # negative_declarative_ordinary_verb_new ___ ___ ___ # percentages # positive_question_'know'_class_old ___ ___ ___ # positive_question_'know'_class_new ___ ___ ___ # percentages # the dot in the first line is a placeholder for the row headers echo -n ". " # the next lines set up the column headers echo -n "1500-1519 " echo -n "1520-1539 " echo -n "1540-1559 " # include the following line at the end of every row for the spreadsheet echo "" # when you import the file into a spreadsheet program, space counts as a # possible column, so I'm using underscore to delimit words in the # headers. you could also use hyphens, periods, etc. echo -n "negative_declarative_ordinary_verb_old " echo -n "`grep -c '^V:.:.:.:.:.:.:.:.:.:5:[01]' ling300.cod.ooo` " echo -n "`grep -c '^V:.:.:.:.:.:.:.:.:.:5:[23]' ling300.cod.ooo` " echo -n "`grep -c '^V:.:.:.:.:.:.:.:.:.:5:[45]' ling300.cod.ooo` " echo "" echo -n "negative_declarative_ordinary_verb_new " echo -n "`grep -c '^v:.:.:.:.:.:.:.:.:.:5:[01]' ling300.cod.ooo` " echo -n "`grep -c '^v:.:.:.:.:.:.:.:.:.:5:[23]' ling300.cod.ooo` " echo -n "`grep -c '^v:.:.:.:.:.:.:.:.:.:5:[45]' ling300.cod.ooo` " echo "" echo -n "percentages" echo "" echo -n "positive_question_'know'_class_old " echo -n "`grep -c '^.:K:p:.:.:.:.:.:.:.:5:[01]' ling300.cod.ooo` " echo -n "`grep -c '^.:K:p:.:.:.:.:.:.:.:5:[23]' ling300.cod.ooo` " echo -n "`grep -c '^.:K:p:.:.:.:.:.:.:.:5:[45]' ling300.cod.ooo` " echo "" echo -n "positive_question_'know'_class_new " echo -n "`grep -c '^.:k:p:.:.:.:.:.:.:.:5:[01]' ling300.cod.ooo` " echo -n "`grep -c '^.:k:p:.:.:.:.:.:.:.:5:[23]' ling300.cod.ooo` " echo -n "`grep -c '^.:k:p:.:.:.:.:.:.:.:5:[45]' ling300.cod.ooo` " echo "" echo -n "percentages" echo ""
chmod 755 spreadsheetGenerator.sh
Once again, if the above command gives you an error message, try the following options.bash spreadsheetGenerator.sh
./spreadsheetGenerator.sh
spreadsheetGenerator.sh
bash spreadsheetGenerator.sh > firstSpreadsheet