Linux Advanced Commands (D): text search command, can be used to know the command text search

Text search command


learning target

  • To know the commands used in text search

Use 1. grep command

command Explanation
grep Text search

grep command renderings:

[Image dump the chain fails, the source station may have security chain mechanism, it is recommended to save the picture down uploaded directly (img-L7Gbca7D-1583934593482) (imgs / grep.png)]

Use 2. grep command options

Command Options Explanation
-i Ignore case
-n Display line numbers match
-v Display does not contain matching text of all lines

-i command options renderings:

[Image dump the chain fails, the source station may have security chain mechanism, it is recommended to save the picture down uploaded directly (img-8E7wLr35-1583934593482) (imgs / grep% E9% 80% 89% E9% A1% B9-1.png )]

-n command option renderings:

[Image dump the chain fails, the source station may have security chain mechanism, it is recommended to save the picture down uploaded directly (img-9apOfT1G-1583934593483) (imgs / grep% E9% 80% 89% E9% A1% B9-2.png )]

-v command options renderings:

[Image dump the chain fails, the source station may have security chain mechanism, it is recommended to save the picture down uploaded directly (img-IUxVf76n-1583934593483) (imgs / grep% E9% 80% 89% E9% A1% B9-3.png )]

3. grep command in conjunction with regular expressions

Regular Expressions Explanation
^ Beginning with the specified string
$ End with the specified string
. A non-matching character newline

Regular expression '^' renderings:

[Image dump the chain fails, the source station may have security chain mechanism, it is recommended to save the picture down uploaded directly (img-WDeyFAy2-1583934593483) (imgs / grep% E6% AD% A3% E5% 88% 99-1.png )]

Regular expression '$' renderings:

[Image dump the chain fails, the source station may have security chain mechanism, it is recommended to save the picture down uploaded directly (img-JxUgsK7w-1583934593484) (imgs / grep% E6% AD% A3% E5% 88% 99-2.png )]

'.' Renderings regular expression:

[Image dump the chain fails, the source station may have security chain mechanism, it is recommended to save the picture down uploaded directly (img-qLvVjREr-1583934593484) (imgs / grep% E6% AD% A3% E5% 88% 99-3.png )]

4. Extension

  • grep command can also search for text content in the pipeline, such as: LS / | grep 'lib'
  • Using grep can also search the contents of quotation marks omitted when the command, such as: LS / | grep lib , grep the Hello 1.txt

5. Summary

  • grep command is completed text search operation
  • Format text search: grep text search options content
Published 698 original articles · won praise 917 · views 120 000 +

Guess you like

Origin blog.csdn.net/qq_35456045/article/details/104806789