Linux Regular expressions

Source: Internet
Author: User

The following grep- based regular; for awk and sed Much the same, a small part is different:

regular expressions are used to quickly filter and replace some specific strings in a unit of behavior Regular expressions are case-sensitive and areGreptime can be added- I.Case insensitive . .represents and can only be any one character, such as the letter in the file name is.can also represent a hidden file,you can also indicate that all rows are filtered asgrep-n. Nginx. Conf-nindicates the line number before each line is filtered. In regular expressions.*does not mean the match all, actually represents duplicates0One or more of the preceding characters, such as filtering2300056, you can usegrep"230*56" can match 2356 23056 230056 2300056 23000..56

. * matches all characters ^.* starts with any character. [] means match any one of the characters. [^] denotes any character content other than [] , not a matching line.

the following if use egrep can remove \ Line

a\{n,m\} repeats n to m times, before a repeating character.

\{n,\} repeats at least n times, preceding a repeating character.

\{n\} repeats n times, before a repeating character.

an extended regular expression: Ere

+ Repeat one or more of the preceding characters with egrep or grep-e

? of 0 or 1 a preceding character

| find multiple matching strings in a way or

() Find the user group string

Enterprise interview: Remove network card Ip

Ifconfig eth0 |sed-n ' /inet addr/ ' |cut-d ' : ' -f2 |cut-d ' ' -f1 or use

Ifconfig eth0 |grep'inet Addr'|awk-f'[: ]+' '{print $4}'+ means match more than any character here represents a space before matching inet for multiple spaces. Simple Direct awk {nr==2} when a line number is in awk

^.*addr: Begins with any character addr: End bc.*$ begins with Bc with any character ending

following Sed

' s#^.*addr:\ (. *\)  bca.*$#\1#g ' p remove the front parenthesis ( .*\ ADDR ip sed take out what you need in a row


Linux Regular expressions

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.