Drainage pits: Regular expressions used in operation and maintenance

Source: Internet
Author: User

First, awk extracts the string method between the double quotes:
such as text: speed= "1000"

Echo ' speed= ' 1000 ' | Awk-f ' "' {print $} '

You can also use sed:

Echo ' speed= ' 1000 ' | Sed-e ' s/. "([0-9]+)". /\1/'

Second, the shell uses the regular extraction of the data inside the parentheses:
As an example:

Su-mqm-c ' echo ' dis qmstatus conns "| RUNMQSC MQXXX999 ' | grep qmname
Qmname (MQXXX999) STATUS (RUNNING)
We're going to just extract MQXXX999 how to do it?
Su-mqm-c ' echo ' dis qmstatus conns "| RUNMQSC MQXXX999 ' | grep Qmname | Sed "s/. Qmname ([0-9a-za-z]). */\1/g "
MQXXX999

Methods for extracting the trailing or preceding values of commas, colons, and other symbols:
As an example:
/bin/echo "Db.serverstatus ()" |/data/software/zabbix tool/mongodb-linux-x86_64-ubuntu1604-3.6.7/bin/mongo 192.168.1.100:29017/chenchen-ulichao-pchenchen | grep ' "Getmore" '
The output is:

We want to extract the value 2 How to extract it?
Add a Awk-f "[,]" ' {print $} ' to the rear. If you want to split awk-f "[:]" ' {print $} ' with a colon. Okay, that's it. This follow-up will be updated.

Drainage pits: Regular expressions used in operation and maintenance

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.