Meta characters are those that have special meaning when used within a regular expression. You already have seen two meta characters used as position specifiers. A list of other meta characters and their meanings is shown in Table 6-2.
Character | Description |
---|---|
* | Matches any number of characters, including zero. |
. | Matches any character, one at a time. |
[] | One of the enclosed characters is matched. The enclosed characters may be a list of characters or a range. |
{ n 1 , n 2\\ | Matches minimum of n 1 and maximum of n 2 occurrences of the preceding character or regular expression. |
\< | Matches at the beginning of the word. |
\> | Matches at the end of the word. |
\ | The character following acts as a regular character, not a meta character. It is used for escaping a meta character. |
The asterisk character is used to match zero or more occurrences of the preceding characters. If you take our example of myfile , the result of the following grep command will be as shown below.
$ grep mom* myfile name which is more convenient as ITO automatically takes modified. It needs to be modified to make more meaningful. $
Is this what you were expecting? The grep command found all text patterns that start with " mo " and after that have zero or more occurrences of the letter m . The words that match this criteria are "more," and "modified." Use of * with only a single character is meaningless as it will match anything. For example, if we use m* , it means to match anything that starts with any number of " m " characters including zero. Now each word that does not start with the letter " m " is also matched because it has zero occurrences of " m ". So one must be careful when using the asterisk ( * ) character in regular expressions.
The dot character matches any character excluding the new line character, one at a time. See the example below where we used the dot to match all words containing the letter " s " followed by any character, followed by the letter " e ".
$ grep s.e myfile new template is completed in three steps. If step 3 is successful, a message appears on ITO The template will not work if the node name specified specified batch_server which was unknown to ITO server current node name if the name is not specified in the 1- It runs every minute. Scans the file only if it is 2- User initiated action is specified to run restart $
In every line shown above, there is a word containing an " s " followed by another character and then " e ". The second-to-last line is of special interest, where this letter combination occurs when we combine the two words " runs every ." Here " s " is followed by a space and then an " e ".
Consider that you want to list all files in a directory that start with the letters a , b , c , d , or e . You can use a command such as:
$ ls a* b* c* d* e*
This is not convenient if this list grows. The alternate way is to use a range pattern like the following.
$ ls [a-e]*
Square brackets are used to specify ranges of characters. For example, if you want to match all words that contain any of the capital letters from A to D , you can use [A-D] in the regular expression.
$ grep [A-D] myfile 1- Create a new template. 2- Assign this template to a node with this procedure. Action -> Agents -> Assign Templates -> Add -> Enter 3- After assignment, the template is still on the ITO Action -> Agents -> Install/Update SW & Config -> IMPORTANT 3- A short instruction is provided to run the script. $
Similarly, if you need to find words starting with lowercase vowels , [aeiou] will serve the purpose. If such words are desired to be at the beginning of a line, we can use ^[aeiou] . Multiple ranges can also be used, such as ^A[a-z0-9] , which matches words that are at the start of a line, has " A " as the first character, and either a lowercase letter or a number as the second character.
The selection criteria can also be reversed using ^ as the first character within the square brackets. An expression [^0-9] matches any character other than a number.
These two sets of meta characters can be used to match complete words. The \< character matches the start of a word and \> checks the end of a word. Without these meta characters, all regular expressions match a string irrespective of its presence in the start, end, or middle of a word. If we want to match all occurrences of " this " or " This " as a whole word in a file, we can use the following grep command.
$ grep \<[tT]his\>
If you use \< only, the pattern is matched if it occurs in the start of a word. Using only \> matches a pattern occurring in the end of a word.
Top |