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"