To interpret the pattern as an extended regular expression, use the -E ( or -extended-regexp) option. In its simplest form, when no regular expression type is given, grep interpret search patterns as basic regular expressions. GNU grep supports three regular expression syntaxes, Basic, Extended, and Perl-compatible. A pattern consists of operators, constructs literal characters, and meta-characters, which have special meaning. Grep Regular Expression #Ī regular expression or regex is a pattern that matches a set of strings.
#GREP MANUAL HOW TO#
In this article, we’re going to explore the basics of how to use regular expressions in the GNU version of grep, which is available by default in most Linux operating systems. grep searches one or more input files for lines that match a regular expression and writes each matching line to standard output. As you can imagine, you can launch all sorts of weird and wonderful quests by combining the functionality that these utilities provide.Grep is one of the most useful and powerful commands in Linux for text processing.
Many other possible applications of the clever grep are there to explore in much more detail, such as back-references, but I hope your appetite has been sufficiently whetted for you to invest more time in brushing up on the basics and less time referencing instruction manuals. There's nothing like getting back to basics sometimes. My intention within this article was to provide enough information related to grep to assist you in building useful command lines and creating invaluable time-saving shell scripts. (The apt-cache search command has related functionality.) Both goodies are highly useful for performing maintenance on servers. In a similar grep-like format, dglob dutifully generates a list of package names that match a pattern. Where binutils is the package you are investigating.Īnother goodie is dgrep, which allows you to search all files in an installed package using regular expressions. To run the utility, all you do is enter which-pkg-broke binutils This utility along with the mighty dpkg can help you solve intricate problems with packages that aren't behaving properly. If you rummage deeper into this bag of goodies, you will discover a tiny utility called which-pkg-broke, which lets you delve into the innards of a package's dependencies and when they were updated.
#GREP MANUAL INSTALL#
To install, enter: # apt-get install debian-goodies The first line is within one error of "gold" (good), the second line is within two errors (volu), and the third line matches exactly (gold).įigure 10: The tre-agrep command outputs three lines in simplefile that match within a distance of two (-2) the word "gold," with case ignored (-i).Īs if all that information about grep isn't enough, a Debian-specific package offers even more grep derivatives in debian-goodies Figure 10 shows the output from this case-insensitive ( -i) command. Therefore, it would return mistakes like "göld" with a diacritical. Means it will accept patterns within two errors of the original pattern. A numeric switch between and 9 tells tre-agrep how many errors to accept, so adding -2 # tre-agrep -2 -i "you" simplefile You could try out tre-agrep with the word "gold" on the simplefile example file. To install libtre5 and tre-agrep on Debian or Ubuntu, use: # apt-get install tre-agrep If you employ the slick regex matching library TRE, you can install a more powerful version of agrep called tre-agrep. , command utilizes fuzzy logic to find matches.
, or ngrep, which offers features similar to tcpdump, as well as a few additional features on top.
#GREP MANUAL SOFTWARE#
For example, are you familiar with vgrep, or visual grep, which takes place when you quickly check something with your eyes instead of using software to perform the task?īack in the realm of the command line, you might have come across the excellent and regular-expression-friendly network grep Thanks to grep's pervasive acceptance, the sys admin's vernacular even includes some highly amusing references in its lexicon. From within this clever editor, you could run a command starting with g that enabled you to print (with p) all the matches of a pattern: # g/chrisbinnie/pįrom these humble beginnings, a standalone utility called grep surfaced, toward which you could pipe any data. The easy-to-use ed was very similar to vi and vim in the sense that it used the same set of colon-based commands. Back in the day, grep was actually a function of the somewhat old-school editor ed. The various incarnations of grep have taken many forms.