Editing Meeting-20100612
Warning: You are not logged in.
Your IP address will be recorded in this page's edit history.The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 42: | Line 42: | ||
sys 0.12 | sys 0.12 | ||
− | grep -c . filename | + | time -p grep -c . filename |
3000000 | 3000000 | ||
real 0.94 | real 0.94 | ||
Line 171: | Line 171: | ||
Let's pick apart the regex to see what it does. | Let's pick apart the regex to see what it does. | ||
− | |||
;^ | ;^ | ||
:The ^ at the beginning means that our regex will only match starting at the beginning of the line. The anticipated use for this command is something like 'echo "$value" | grep blah...', so we know there won't be any extraneous stuff at the beginning. If you are getting the value from a file or as input from the user, you may need to strip away whitespace from the beginning, or alter the regex to account for that. | :The ^ at the beginning means that our regex will only match starting at the beginning of the line. The anticipated use for this command is something like 'echo "$value" | grep blah...', so we know there won't be any extraneous stuff at the beginning. If you are getting the value from a file or as input from the user, you may need to strip away whitespace from the beginning, or alter the regex to account for that. | ||
− | |||
;[-+] | ;[-+] | ||
:An expression inside brackets matches a single character, as long as that character is one of those listed inside the brackets (a range of characters can be specified, as can special pre-defined character classes, but in this case we're not using either of those). So this would match either a - sign or a + sign. Note that inside a bracket expression, + has no special meaning. | :An expression inside brackets matches a single character, as long as that character is one of those listed inside the brackets (a range of characters can be specified, as can special pre-defined character classes, but in this case we're not using either of those). So this would match either a - sign or a + sign. Note that inside a bracket expression, + has no special meaning. | ||
− | |||
;[-+]? | ;[-+]? | ||
:The question mark means "match zero or one of the preceding character." This makes it so that having a sign at the beginning of our number is optional, and also disallows multiple sign characters. | :The question mark means "match zero or one of the preceding character." This makes it so that having a sign at the beginning of our number is optional, and also disallows multiple sign characters. | ||
− | |||
;( ... | ... ) | ;( ... | ... ) | ||
:The parentheses are there for grouping what's inside as a single unit. The pipe symbolizes alternation - that is, this part of the regex will match either the expression appearing before the pipe symbol, or the expression appearing after it. We need to use alternation because while it is optional to have numbers before the decimal point (e.g., .123) or after the decimal point (e.g., 123.), it is not valid for both sets of numbers to be missing (e.g., just a .). | :The parentheses are there for grouping what's inside as a single unit. The pipe symbolizes alternation - that is, this part of the regex will match either the expression appearing before the pipe symbol, or the expression appearing after it. We need to use alternation because while it is optional to have numbers before the decimal point (e.g., .123) or after the decimal point (e.g., 123.), it is not valid for both sets of numbers to be missing (e.g., just a .). | ||
− | |||
;[0-9] | ;[0-9] | ||
:Another bracket expression, this matches any single numeral (that is, any character in the range 0 through 9). | :Another bracket expression, this matches any single numeral (that is, any character in the range 0 through 9). | ||
− | |||
;[0-9]+ | ;[0-9]+ | ||
:The + sign outside a bracket expression does have special meaning. It means "match one or more of the preceding character." So this will match one or more numerals, but not an empty string. | :The + sign outside a bracket expression does have special meaning. It means "match one or more of the preceding character." So this will match one or more numerals, but not an empty string. | ||
− | |||
;\. | ;\. | ||
:The dot has the special meaning "match any character." If we want to literally match a period, we have to escape it with a backslash to remove its special meaning. Note that '''[.]''' would do the same thing, as dot has no special meaning inside a bracket expression. | :The dot has the special meaning "match any character." If we want to literally match a period, we have to escape it with a backslash to remove its special meaning. Note that '''[.]''' would do the same thing, as dot has no special meaning inside a bracket expression. | ||
− | |||
;\.? | ;\.? | ||
:Again, question mark means to match zero or one of the preceding character. This makes the decimal point optional. | :Again, question mark means to match zero or one of the preceding character. This makes the decimal point optional. | ||
− | |||
;[0-9]+\.? | ;[0-9]+\.? | ||
:This is the entire first expression of our alternation. It will match an integer of any length, optionally followed by a decimal point. So 0, 123, 123., 00000., 000123, and 123123123123123123123 would all match, but just a decimal point would not. | :This is the entire first expression of our alternation. It will match an integer of any length, optionally followed by a decimal point. So 0, 123, 123., 00000., 000123, and 123123123123123123123 would all match, but just a decimal point would not. | ||
− | |||
;[0-9]* | ;[0-9]* | ||
:We've seen [0-9] before, but the * is new. It is similar to +, but means "match zero or more of the preceding character." We use * instead of + because it's valid to have nothing in front of the decimal point (e.g., .123). | :We've seen [0-9] before, but the * is new. It is similar to +, but means "match zero or more of the preceding character." We use * instead of + because it's valid to have nothing in front of the decimal point (e.g., .123). | ||
− | |||
;\. | ;\. | ||
:This matches a decimal point again, but note there is no question mark. In this expression, one single decimal point is mandatory. | :This matches a decimal point again, but note there is no question mark. In this expression, one single decimal point is mandatory. | ||
− | |||
;[0-9]+ | ;[0-9]+ | ||
:Again, this matches one or more numerals. Having numbers after the decimal point is not optional here. | :Again, this matches one or more numerals. Having numbers after the decimal point is not optional here. | ||
− | |||
;[0-9]*\.[0-9]+ | ;[0-9]*\.[0-9]+ | ||
:This is the full second expression of our alternation. It will match any floating point value, such as 0.123, 1.234, .123, 0098.6, 123.456, or 3.1415926535897932384626433832795028841971693993751. | :This is the full second expression of our alternation. It will match any floating point value, such as 0.123, 1.234, .123, 0098.6, 123.456, or 3.1415926535897932384626433832795028841971693993751. | ||
− | |||
;([0-9]+\.?|[0-9]*\.[0-9]+) | ;([0-9]+\.?|[0-9]*\.[0-9]+) | ||
:This is the full non-sign part of our regex. As discussed above regarding alternation, it means "either an integer, optionally followed by a decimal point, or an optional set of numerals followed by a (mandatory) decimal point and one or more trailing numerals." | :This is the full non-sign part of our regex. As discussed above regarding alternation, it means "either an integer, optionally followed by a decimal point, or an optional set of numerals followed by a (mandatory) decimal point and one or more trailing numerals." | ||
− | |||
;$ | ;$ | ||
:This is the counterpart to the ^ character, forcing a match at the end of the line. Putting the expression inside ^$ forbids any extraneous characters before or after our match. | :This is the counterpart to the ^ character, forcing a match at the end of the line. Putting the expression inside ^$ forbids any extraneous characters before or after our match. |