The Linux shell writes regex pattern recognition string words __linux

Source: Internet
Author: User

string: AA bb cc DD

Requirements: The word in the output string

Pattern 1:

*@*:~$ echo AA bb cc DD |GREP//b//w*//b

RESULT:AA BB cc DD

Pattern 2: Substituting the + number for *

*@*:~$ echo AA bb cc DD |GREP//b//w+//b

Result: No output

What's the problem, right? + to escape, add a/

Pattern 3:

*@*:~$ echo AA bb cc DD |GREP//b//w/+//b

Result: There is still no output

What's going on here, get it, get it, just know what's going on, look underneath it.

Pattern 4:

*@*:~$ echo AA bb cc DD |GREP//b//w//+//b

RESULT:AA BB cc DD

Finally give a shell command that calculates the number of words

echo AA bb cc dd |SED-E s///b//w//+//b/x/g | SED-E s///s//g | Wc-m (doesn't seem to be right, the output is 5, but actually there are only 4)

I hope you will not doubt

Related Article

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.