Linux grep command introduction and practical operations (1)

Source: Internet
Author: User

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)


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.