
In the following example, the text string will match only if it occurs at the very beginning of a line. Use the ^ (caret) symbol to match expression at the start of a line. grep -r string -include= filename -include= *.php -include= folder/* folder-name Regular Expression Search You can use the -include option to include only the specific directories, specific files or files with specific extensions. grep -r string -exclude= filename -exclude= *.png -exclude= folder/* folder-name Include Files while using grep You can use the -exclude option to exclude directories, specific files or files with specific extensions. Grep -R string folder-name Exclude Files while using grep
If you wish to search over symbolic links you need to use the capital -R option instead of small -r option. The -r option don’t follow the symbolic links. To search through all the files that are inside the directory you need to use the -r option to perform a recursive search within the given folder. This command will search for the given text inside the provided file and output the results. Just use the command with the string you need to search for and the file name. This is the most basic usage of grep command. If you want to ignore case you can use the -i option which ignores case sensitive and outputs the content which has lowercase and uppercase. If you walk through the docs, you'll find a lot more *nix-like command-line tools, including cut, tr, and on the 7K, sed and some other goodies.Īlso, don't overlook the prev and next modifiers for 'include' matches.By default grep is case sensitve. You'll then want to search "fun" (what else?) to find the Fundamentals Configuration Guide (which contains the Regular Expression section in the Understanding the Command-Line Interface chapter).Įaster egg? Chapter numbers are in binary for this doc.
Note that the docs may be version and platform dependent.Ĭisco Nexus 7000 Series Switches Configuration GuidesĬisco Nexus 5000 Series Switches Configuration Guides. Word-exp Print only lines where the match is a complete word Prev Print lines of context before every matching line Next Print lines of context after every matching line Line-number Print each match preceded by its line number Invert-match Print only lines that contain no matches for Line-exp Print only lines where the match is a whole lineĬount Print a total count of matching lines only Ignore-case Ignore case difference when comparing strings Vsh The shell that understands cli command Uniq Discard all but one of successive identical lines Tr Translate, squeeze, and/or delete characters Section Show lines that include the pattern as well as the subsequent lines that are more No-more Turn-off pagination for command output Grep Grep - print lines matching a pattern With 'diff-clean' command and dont use it on commands with big outputs, like 'showĮgrep Egrep - print lines matching a pattern The basic Cisco documentation is here*, but your command-line ? feature gives you quick reminders: 5k# show run | ?ĭiff Show difference between current and previous invocation (creates temp files: remove them Nevertheless, there is considerably more power and flexibility here than in current IOS. This would be equivalent to a bash-shell egrep -i vpc | egrep -vi peer Show run | egrep ignore-case vpc | egrep invert-match ignore-case peer On the command line this would look something likeĪn example of the verbosity (and strength) of the new regex features: The commands are odd comprises between English wording and standard regex idioms.įor example, what would be egrep -v in bash would look like egrep ignore-case NX-OS is Linux-based, and uses a *nix-like regular expression engine. The key in this example is that for NX-OS, the parens are replaced by quote marks. Show run | inc (interface Vlan|ip address) Note that this makes more sense when you leave out the extra parens in the original: NX-OS: show run | inc 'interface Vlan|ip address' IOS: show run | inc (interface Vlan)|(ip address) The easy answer is that, for a one-to-one mapping from IOS to NX-OS, it looks like this: