SYNOPSIS
OPTIONS
DESCRIPTION
Regular ExpressionsThe search string is the only required argument to hgrep. Optionally, a list of files to search can follow the search string, or if there are no files listed after the search string, then input data will be read from standard input (such as a piped data from another command). By default, both the basic and extended regular expression sets of meta characters are can be used in the search string. But the basic set can be used instead if you specify the -G option. Here are a list of the regular-expression operations:
Examples: Search for notes which are equal to or higher than C5: hgrep -kd '[a-g]{2,}' file.krn Search for starting or ending phrase marks: hgrep -kd '\{|\}' file.krn hgrep -Gkd '{\|}' file.krn Search for C-naturals, but not C# or C-flats (The -i option ignores the case of letters, so capital or lowercase text will match to the search string.): hgrep -kid 'c+([^#-]|$)' file.krn hgrep -kd '[Cc]+([^#-]|$)' file.krn Search for quarter notes (but not, for example, rhythm values of 24 (triplet sixteenths)): hgrep -kd '(^|[^0-9])4([^0-9]|$)' file.krn If you want to search for a character which also serves as a regular expression operator, then place a backslash before the character. For example \+ will search for a plus character, while + without the backslash will be interpreted as the operator which matches to one ore more of the preceding atom. Note that if you use the -G option, the extended regular expression operators are not recognized as being special characters, so the non-backslashed versions are literal characters. However, if you add a backslash in front of one of these characters, then it will be treated as an extended-regular expression operator. For example, the meanings of + and \+ are reversed when using the -G option. This is helpful in cases when searching for characters which normally are used in regular expresssions, avoiding adding backslashes which make it more difficult to read the regular-expression (such as the phrase-mark example above). For more information about regular expressions, search for the term in a search engine (such as on Google.com) or read the regular expression page on Wikipedia. Location informationThe options -a, -b, -f, -m, -n, and -s will display information about the location of a match in the Humdrum file. The location information will be displayed in front of the matched line.
Any of these options can be mixed and matched. The options -a, -b and -f require data which can be parsed rhythmically, such as **kern data, in order to work. The options -n and -s can be used with any type of data, and -m (measure number) can be used when measures are labeled with numbers in the data file. Location information will be separated from the matched line and other location information fields by a colon character (:). This separator can be change to another string by using the --sep option. --sep "\t" can be used to separate information with tabs, and --sep "\n" to use the newline character.
Adding measure numbers before using -mThe measure location of matches reported when using the -m option requires a number attached to each barline. If there are no numbers on the barlines, then -m will not return useful results (measure number for any match will be 1). To add measure numbers beforehand, you can use the barnum command:
Barlines which split a full measure are labeled as the same measure before and after the incomplete measure barline:
Selective search regionsSearching can be limited to certain types of lines or spines belonging to particular exclusive interpretation. To only search in data lines, ignoring global/bibliographic comments, local comments, interpretations or measure lines, use the -d option. This is analogous to using the Humdrum Toolkit command rid -GLId before searching with grep. To search only in **kern spines, use the -k option. This will search any type of token in **kern spines, for example: local comments, interpretations, barlines, and musical data. Global comments and bibliographic records will be ignored when using the -k option. To search only in **kern data tokens, ignoring local comments, interpretations and barlines, combine the -k and -d options: hgrep -kd 4 file.krnwhich will search for all rhythms containing a "4" in the **kern data. The -k option is shorthand for the more verbose option: -x "**kern" which only searching in **kern spines. You can list more than one exclusive interpretation type in the argument to the -x option. For example, -x "**text, **silbe" will search only in spines which belong to **text or **silbe exclusive interpretations, while all other types of spines will be ignored. Alternative formats of the -x option which behave the same way: -x "**text **silbe" and -x "**text**silbe". Note that the exclusive interpretation list only has to match the starting portion of an exclusive interpretation, so -x "**dyn" will search in both **dyn and **dynam spines. The -t option works similarly to the -d option, except that only tandem interpretations are searched, while other types of lines are ignored. This option might be useful, for example, when searching for the location of metronome markings in **kern data: hgrep -tk '^.MM[0-9.]+$' file.krn Here is another example of using the tandem search to count the number of clef changes present in Chopin mazurkas: hgrep -t 'clef' mazurka*.krn | wc -lWhich returns 392 matches, which means that the clef changes 340 times during all of the 52 mazurkas were searched, or about 6.5 times per mazurka. If you want to only search in comment records (global comments, bibliographic records, or local comments), then use the -c option. Both -d and -t option can be used at the same time, but -c cannot be used together with either of those two options. If you want to only search in bibliographic records, but not in local comments or other global comments, then use the -B option. The -f option combined with the -B option can be useful to determine if bibliographic records are found before, after or in the middle of the data file:
In the above example, bibliographic records found before the first data line (either before or after the first exclusive interpretation line) are labeled with "frac 0.000. lines which occur after the last data token (either before or after the last interpretation lines) are labeled with "frac 1.000. Bibliographic records occurring somewhere in the middle of the data records in the file will be labeled with a fractional value between 0.000 and 1.000. --and UsageSeveral searches can be done at the same time which are logically anded together. For example, here is a search for lines of code where there is a note higher than B4 played at the same time as a note lower than C3: hgrep -kd '[a-g]{2,}' --and '[A-G]{2,}' file.krn Multiple anded searches can be done at the same time. For example, here is a search for lines which contain the three diatonic pitch classes C, E, and G on the same line: hgrep -kid 'c' --and 'e\ng' file.krnIn the and search string, a newline character or the string "\n" are used to separate searches. If you want to do anded searches located in several data types, you can add and Exclusive interpretation requirement infront of an anded search entry. That exclusive interpretation requirement will apply to all subsequent search strings in the --and list. Here is an example of searching for a diatonic pitch class C which occurs on the same line as **text data containing a vowel: hgrep -kid c --and '**text\n[aeiou]' file.krn hgrep -idx '**kern' c --and '**text\n[aeiou]' file.krn hgrep -idx '**text' '[aeiou]' --and '**kern\nc' file.krn EXAMPLES
ONLINE DATA
program file.krnIt can also read the data over the web: program http://www.some-computer.com/some-directory/file.krnPiped data works in a somewhat similar manner: cat file.krn | programis equivalent to a web file using ths form: echo http://www.some-computer.com/some-directory/file.krn | program Besides the http:// protocol, there is another special resource indicator prefix called humdrum:// which downloads data from the kernscores website. For example, using the URI humdrum://brandenburg/bwv1046a.krn: program humdrum://brandenburg/bwv1046a.krnwill download the URL: Which is found in the Musedata Bach Brandenburg Concerto collection. This online-access of Humdrum data can also interface with the classical Humdrum Toolkit commands by using humcat to download the data from the kernscores website. For example, try the command pipeline: humcat humdrum://brandenburg/bwv1046a.krn | census -k SEE ALSODOWNLOAD
The source code for the program was last modified on 6 Apr 2013. Click here to go to the full source-code download page. |