In the use of Linux, a variety of commands will make everyone very entangled, it is difficult to fully master these commands. Here we will introduce how to use the Linux grep command and some practical application operations. I believe it will be helpful for you to use the Linux grep command.
1. grep Introduction
Grep global search regular expression (RE) and print out the line, comprehensive search for regular expressions and print out rows) is a powerful text search tool, it can use regular expressions to search for text and print matching rows. Unix grep families include grep, egrep, and fgrep. The commands of egrep and fgrep are only slightly different from those of grep. Egrep is an extension of grep and supports more re metacharacters. fgrep is fixed grep or fast grep. They regard all the letters as words, that is, the metacharacters in a regular expression represent the literal meaning of the regular expression. They are no longer special. Linux uses GNU grep. It is more powerful and can use egrep and fgrep functions through the-G,-E,-F command line options.
Grep works like this. it searches for string templates in one or more files. If the template contains spaces, it must be referenced. All strings after the template are treated as file names. The search result is sent to the screen without affecting the content of the original file.
2. POSIX character class
POSIX (The Portable Operating System Interface) adds a special character class, for example [: alnum:] is another way of writing a A-Za-z0-9 to preserve one character encoding in different countries. Put them in the [] sign to become A regular expression, such as [A-Za-z0-9] or [[: alnum:]. In Linux, grep supports POSIX character classes except fgrep.
[: Alnum:]
Character
[: Alpha:]
Character
[: Digit:]
Numeric characters
[: Graph:]
Non-null characters, non-spaces, and control characters)
[: Lower:]
Lowercase characters
[: Cntrl:]
Control characters
[: Print:]
Non-empty characters include spaces)
[: Punct:]
Punctuation Marks
[: Space:]
All blank character new lines, spaces, tabs)
[: Upper:]
Uppercase characters
[: Xdigit:]
Hexadecimal digits 0-9, a-f, A-F)