#1, total number of statistical characters
#统计系统中不允许登录的用户数
Grep-c ' Nologin '/etc/passwd
#2, case-insensitive lookup of all lines of the specified character;
Grep-i ' Good ' 9.txt
#3, print the line and line number of the specified character;
Grep-n "Good" 9.txt
#4, lines that do not print the specified characters
Grep-v "Good" 9.txt
#5, printing begins with a character good, followed by a line of numbers
grep "good[0-9]" 9.txt
#6, lines that match G or G
grep "[Gg]ood" 9.txt
#7, display the line at the beginning of the output that is not good
grep "^[^good]" 9.txt
#8, Match G, two arbitrary characters, immediately following the D line
grep "G.. D "9.txt
#9, match uppercase letters, and follow OO word lines
grep ' [A-z]oo ' 9.txt
#10, print a row with more than n occurrences of the specified character
Grep-n ' o\{2,\} ' 9.txtgrep-n ' o\{3,4\} ' 9.txt
#11, the line number where the blank line is printed
Grep-n "^$" 9.txt
#12, mismatched # and blank lines in a file
Grep-ve ' #|^$ ' httpd.conf
#13, matching files that contain the specified characters
#-r: In the current directory and its subdirectories
#-l: Matching rows are not displayed, only matching files are displayed
Grep-r-n ' good '/home/bel/*grep-r-l ' good '/home/bel/*
#14, Match IPV4 address
Ifconfig | grep--color-e "\< ([0-9]{1,3}\.) {3} [0-9] {1,3}^$\> "
#15,
#显示匹配某个结果之后的3行, use the-a option
#显示匹配某个结果之前的3行, use the-B option
#显示匹配某个结果的前三行和后三行, use the-C option
Seq 10 | grep ' 5 '-a3seq 10 | grep ' 5 '-b3seq 10 | grep ' 5 '-c3
This article is from the "Mo Jing" blog, reproduced please contact the author!
Some uses of shell grep