Use the-O and-e options of grep to exact match the regular expression.

Source: Internet
Author: User

The SED command can perform line matching well, but precisely match certain content from a line, you can use the grep command and the-O and-e options to achieve this purpose. -O indicates "only-matching", that is, "only matching. It is not enough to use it alone. It is very powerful to use extended regular expressions with the-e option.

For example, the following text tmp.txt contains:

{"Aid": 45, "path": "attachment/mon_1112/2_00005728040df3ab346.jpg "}


If we want to obtain the aid value 45, we can do the following first:

Grep-o-e 'aid ": [1-9] * 'tmp.txt


The result is as follows:

Aid ": 45


In this case, we can use the-F option of awk to indicate the colon separator, so that it is easy to filter out the value of 45. The overall command is as follows:

Grep-o-e 'aid ": [1-9] * 'tmp.txt | awk-F: '{print $2 }'

 

Use the-O and-e options of grep to exact match the regular expression.

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.