The grep command retrieves the rows in the file that contain keywords (which can be used), and is case-sensitive by default.
Use the-c parameter to get the number of rows that contain the keyword
Use the-n parameter to display the line number at the same time that the content is printed
Using the-i parameter, when looking, is case insensitive
Use the-v parameter to find rows that do not contain keywords
To use a regular expression, you can use the-e parameter
The shell is similar to the regular Perl language and is basically generic.
[Email protected]:~/test$ cat Test.txtthis is Linuxthis was Linuxthat is apples[email protected]:~/test$ grep-e ' ^that ' t Est.txt #以that开头的行that was apples[email protected]:~/test$ grep-e ' linux$ ' test.txt #以Linux结尾的行this is Linux[email Protec ted]:~/test$ grep-e '. Inux ' Test.txt # '. ' Represents any one character (not including whitespace) This is linuxthis is Linux[email protected]:~/test$ grep-e ' p* ' test.txt
There are also some commonly used matching patterns, such as ' ^$ ' for a blank line, ' ^.$ ' represents a line with only one character, and a \ to escape, such as using \. to match a point; [0-9] means matching a number; [a-z]| [A-z] denotes any letter; use | to denote ' or ';
Shell Script--grep command for content lookup