![]() ![]() ➜ grep -n -w -e "dfff" -e "apple" test6.txt In the first example, we use the grep -e option to match the line containing the word “dfff” or “apple” in the file test6.txt. * Match file containing keyword1 or containing keyword2 … : OR * Match file containing keyword1 and containing keyword2 … : AND But matching multiple keywords has two meanings: Grep matches multiple keywords, which we often use on a daily basis. Sometimes, however, we also need to count the keyword to appear in the file, at the same time, according to the line number in reverse order. In the example above, we can count the number of lines or the total number of occurrences of a keyword in a file. In the following example, the grep directory contains files whose filenames contain the keyword “test”, and we use the ls command, pipe, and wc command to count the number of files whose filenames contain the keyword “test” in the directory. Grep count the number of files in the directory whose filename contains the specified keyword w, -word-regexp The expression is searched for as a word (as if surrounded by `]' see re_format(7)). o, -only-matching Prints only the matching part of the lines. In the following example, we use grep -w to count the number of times of the string “dfff” in the file ➜ grep -o -w "dfff" test6.txt | wc -l Options: Grep counts the number of times of the specified content in a file You can also use the grep command, pipe, and wc command to achieve the same effect as the grep-c option in the following example. Using grep -c options alone will count the number of lines that contain the matching word instead of the number of total matches. In the following example, we will use the grep command to count the number of lines in the file test6.txt that contain the string “dfff” ➜ grep -c "dfff" test6.txt Matches a comma (,), left brace ( ,1300, (1300you can specify simply _1300_.Grep counts the number of lines in the file that contain the specified content Matches 0 or 1 occurrences of the pattern. Matches 1 or more sequences of the pattern. Matchers 0 or more sequences of the pattern. Matches any single character, including white space. The table below lists the keyboard characters that have special meaning. You can also use other keyboard characters (such as ! or ~) as single-character patterns, but certain keyboard characters have special meaning when used in regular expressions. You can use any letter (A-Z, a-z) or digit (0-9) as a single-character pattern. The simplest regular expression is a single character that matches the same single character in the command output. Searching and Filtering from the -More-Prompt.It also discusses creating more complex regular expressions using multipliers, alternation, anchoring, and parentheses. This section describes creating both single-character patterns and multiple-character patterns. The pattern in the command output is referred to as a string. That is, a regular expression can be a single character that matches the same single character in the command output or multiple characters that match the same multiple characters in the command output. , ( is ), or utput.Ī regular expression can be a single-character pattern or a multiple-character pattern. Complex regular expressions include entries like 00210. Simple regular expressions include entries like Serial, misses, or 138. Regular expressions are case-sensitive and allow for complex matching requirements. Understanding Regular ExpressionsĪ regular expression is a pattern (a phrase, number, or more complex pattern) the CLI String Search feature matches against show or more command output. To access Cisco Feature Navigator, go to http://. Use Cisco Feature Navigator to find information about platform support and Cisco IOS and Catalyst OS software image support. Searching and Filtering CLI Output Examples.The CLI String Search feature allows you to search or filter output from -More- prompts. Pressing Return displays the next line pressing the Spacebar displays the next screen of output. When output continues beyond what is displayed on your screen, the Cisco IOS CLI displays a -More- prompt. Show and more commands are always entered in user EXEC or privileged EXEC. These features are enabled for show and more commands, which generally display large amounts of data. The Cisco IOS CLI provides ways of searching through large amounts of command output and filtering output to exclude information you do not need. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |