5th day (half day) "Shell programming preliminary, grep and regular Expressions"

Source: Internet
Author: User

Day 5th (half day) "Shell programming preliminary, grep and regular expression" shell programming preliminary (_RECV)

Shell script: Text file

#!:/ Bin/bash

#!:/ Usr/bin/python

#!:/ Usr/bin/perl

Case Listing 1:

Vim first.sh

#!:/ Bin/bash

Cat/etc/fstab

Wc–l/etc/fstab

Give script permissions Chmod a+x first.sh

Run the script./first.sh

------------------------------------------------------------------

Logical operation:

True

False

And:

1 && 1 =1

1 && 0=0

0 && 1 =0

0 && 0 =0

Or:

1 | | 1= 1

1 | | 0= 1

0 | | 1= 1

0 | | 0 =0

Non -:

! 1 = 0

! 0 = 1

grep and regular Expressions (_RECV)

The Three musketeers of text processing on Linux:

Grep: Text Filtering tool

Sed: Text Editing tools

Awk:

Grep:global search Regular expression and print out of the line

Function: Text Search tool, according to the user-specified mode of the target text line by row to accompany the check;

Grep:

-V: Reverse lookup, which outputs rows that do not match the lookup criteria

Grep root/etc/passwd

-e: extended regular expression;

-G: basic regular expression;

-F: Fixed string

-I: ignore character case;

-O: Displays only the matched string;

Grep–o root/etc/passwd

-Q: Silent mode, do not enter any information

Grep–q root/etc/passwd

-C: Statistics A total number of lines;

-N: Displays line numbers on the left;

-A number: after # line

-B Number: Front # line

-C Number: Before and after # lines

Grep–c ' Nologin ' passwork

Allisa grep= ' Grep–color=auto '

Grep root/etc/passwd

Basic regular Expression meta-characters:

Character Matching:

.: Matches any single character

Grep ' R.ot '/etc/passwd

[]: matches any single character within the specified range

Grep [Root]/etc/passwd

[^]: matches any single character outside the specified range
Grep [^root]/etc/passwd
[0-9]: Statistics in the specified range of numbers
[:d Igit:], [: Lower:], [: Upper:], [: Alpha:], [: Alnum:], [:p UNCT:], [: Space:]
Grep [0-9]/etc/passwd

Number of matches: used after the number of characters to be specified, to specify the number of occurrences of the preceding character;

*: matches the preceding character any time;

For example: grep "X*y"

. *: Any character of any length;

Location anchoring:

^: Anchor at the beginning of the line for the leftmost mode

$: End of line anchoring,

^$: Empty line;

5th day (half day) "Shell programming preliminary, grep and regular Expressions"

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.