Humdrum Lab 3
Perhaps view Humdrum Lab 2 before this lab.
This lab demonstrate using tindex/themax/theloc to search for melodic/rhythmic patterns in **kern scores.
First download the erk songs from Humdrum Lab 2 and the Bach chorales from Humdrum Lab 1.
Split songs into major and minor groups
Similar to the last lab, split the Erk songs into those that are in major and those that are minor:
mkdir major mkdir minor cp `egrep -l '^\*[A-G][#-]?:' *.krn` major cp `egrep -l '^\*[a-g][#-]?:' *.krn` major
The regular expression:
^\*[A-G][#-]?:
means search for a line that starts (^) with an asterisk (\*) followed by one character in the range from A to G ([A-G]) followed optionally by the character '#' or '-' ([#-]?) followed by a colon (:).
Notice the back-quotes in the last two commands. This means to run the command inside of the backquotes first, then use that content as argument input into the rest of the command.
The `-l` option for egrep is used to list the files the contain the match, not the matches themselves.
egrep is used instead of grep, because '?' is an extended regular expression metacharcter. In the basic set of regular expression meta characters, the '?' character is a normal character with no special meaning.
Here are the basic regular-expression operators:
. | Any single character |
* | zero or more occurrences of the previous character |
[] | one of the characters in the enclosed list |
^ | anchor match to start of line |
$ | anchor match to the end of line |
After the basic set was developed, people wanted more operators, so an extended set was added:
+ | one or more occurrences of the previous character |
() | grouping, such as (cat)+ which would match to cat, catcat, catcatcat, etc. |
| | logical or operator, such as (cat|mouse) which would match to cat or mouse. |
{} | generalize counter, such as {3,5} meaning between three and five occurrences of the previous character or parentheses grouping. |