[root@service99 ~]# mkdir /opt/regular [root@service99 ~]# cd /opt/regular [root@service99 regular]# pwd /opt/regular [root@service99 regular]# cp /etc/passwd temp_passwd
//grep --color 主要是可以将匹配到的文本高亮显示,这样便于观察效果 [root@service99 regular]# grep --color "root" temp_passwd root:x:0:0:root:/root:/bin/bash operator:x:11:0:operator:/root:/sbin/nologin
[root@service99 regular]# ifconfig eth1 | grep --color "add"
eth1 Link encap:Ethernet HWaddr 54:52:01:01:99:02
inet addr:192.168.2.99 Bcast:192.168.2.255 Mask:255.255.255.0
inet6 addr: fe80::5652:1ff:fe01:9902/64 Scope:Link
[root@service99 regular]# echo "This is line number 1" | grep --color "ber 1" This is line number 1
[root@service99 regular]# echo "This cat is $4.99" //双引号不会屏蔽特殊符号,所以系统会读取变量4.99的值,然而当前系统并没有该变量,就显示为空 This cat is .99 [root@service99 regular]# echo "This cat is \$4.99" //使用"\"转义$ This cat is $4.99 [root@service99 regular]# echo 'This cat is \$4.99' //单引号屏蔽元字符$ This cat is \$4.99 [root@service99 regular]# echo 'This cat is $4.99' This cat is $4.99 [root@service99 regular]# cat price.txt This price is $4.99 hello,world! $5.00 #$#$ This is "\". [root@service99 regular]# grep --color '\\' price.txt This is "\".
[root@service99 regular]# grep --color '^h' price.txt //以字母h开头的行 hello,world! [root@service99 regular]# grep --color '^$' price.txt //无输出结果,由于没有屏蔽特殊含义 [root@service99 regular]# grep --color '^\$' price.txt //以$符号开头的行 $5.00 [root@service99 regular]# echo "This is ^ test. " >> price.txt [root@service99 regular]# cat price.txt This price is $4.99 hello,world! $5.00 #$#$ This is "\". This is ^ test. [root@service99 regular]# grep --color '^' price.txt //直接使用会显示所有的内容 This price is $4.99 hello,world! $5.00 #$#$ This is "\". This is ^ test. [root@service99 regular]# grep --color '\^' price.txt //单独使用,并在最前面时需要屏蔽 This is ^ test. [root@service99 regular]# grep --color 'is ^' price.txt //符号不在最前面时,无需屏蔽,直接使用即可 This is ^ test.
[root@service99 regular]# grep --color '\.$' price.txt //“.”在正则表达式中也有特殊含义,请屏蔽,具体的请往下看 This is "\". [root@service99 regular]# grep --color '\. $' price.txt //由于我在输入的时候,多加了一个空格,所以各位需要慎重和小心 This is ^ test. //在正则表达式中,空格作为字符计。 [root@service99 regular]# grep --color '0$' price.txt $5.00 [root@service99 regular]# grep --color '9$' price.txt This price is $4.99
[root@service99 regular]# cat -n /etc/vsftpd/vsftpd.conf | wc -l 121 [root@service99 regular]# grep -vE '^#|^$' /etc/vsftpd/vsftpd.conf //v表示反选,E表示支持扩展正则“|”是扩展正则的符号,往下看,后面有 anonymous_enable=YES local_enable=YES write_enable=YES local_umask=022 anon_upload_enable=YES anon_mkdir_write_enable=YES anon_other_write_enable=YES anon_umask=022 dirmessage_enable=YES xferlog_enable=YES connect_from_port_20=YES xferlog_std_format=YES listen=YES pam_service_name=vsftpd userlist_enable=YES tcp_wrappers=YES
[root@service99 regular]# grep --color "12345\{0,1\}" price.txt
1234556
[root@service99 regular]# grep --color "12345\{0,2\}" price.txt
1234556
[root@service99 regular]# grep --color ".s" price.txt This price is $4.99 This is "\". This is ^ test. [root@service99 regular]# grep --color ".or" price.txt hello,world!
[root@service99 regular]# grep --color "[abcdsxyz]" price.txt This price is $4.99 hello,world! This is "\". This is ^ test. [root@service99 regular]# grep --color "[sxyz]" price.txt This price is $4.99 This is "\". This is ^ test. [root@service99 regular]# grep --color "[abcd]" price.txt This price is $4.99 hello,world! [root@service99 regular]# grep --color "Th[ais]" price.txt //Th 后的第一个字符在【ais】中匹配的 This price is $4.99 This is "\". This is ^ test. [root@service99 regular]# grep -i --color "th[ais]" price.txt //-i 表示不区分大小写 This price is $4.99 This is "\". This is ^ test.
[root@service99 regular]# echo "Yes" | grep --color "[yY]es" []内字符顺序没有影响 Yes [root@service99 regular]# echo "yes" | grep --color "[Yy]es" yes
[root@service99 regular]# echo "Yes/no" | grep "[Yy][Ee]" Yes/no [root@service99 regular]# echo "Yes/no" | grep "[Yy].*[Nn]" //*在正则表达式中的用法,请往下看 Yes/no
[root@service99 regular]# echo "My phone number is 123456987" | grep --color "is [1234]" My phone number is 123456987 [root@service99 regular]# echo "This is Phone1" | grep --color "e[1234]" This is Phone1 [root@service99 regular]# echo "This is Phone1" | grep --color "[1]" This is Phone1
[root@service99 regular]# echo "regular" | grep --color "r[ea]g[ua]l[ao]" regular
[root@service99 regular]# cat price.txt This price is $4.99 hello,world! $5.00 #$#$ This is "\". this is ^ test. cat car [root@service99 regular]# sed -n '/[^t]his/p' price.txt This price is $4.99 This is "\". [root@service99 regular]# grep --color "[^t]his" price.txt This price is $4.99 This is "\". [root@service99 regular]# grep --color "ca[tr]" price.txt cat car [root@service99 regular]# grep --color "ca[^r]" price.txt cat
[root@service99 regular]# cat price.txt This price is $4.99 hello,world! $5.00 #$#$ This is "\". this is ^ test. cat car 1234556 911 11806 [root@service99 regular]# egrep --color '[a-z]' price.txt This price is $4.99 hello,world! This is "\". this is ^ test. cat car [root@service99 regular]# egrep --color '[A-Z]' price.txt This price is $4.99 This is "\". [root@service99 regular]# grep --color "[0-9]" price.txt This price is $4.99 $5.00 1234556 911 11806 [root@service99 regular]# sed -n '/^[^a-Z]/p' price.txt $5.00 #$#$ 1234556 911 11806 [root@service99 regular]# grep --color "^[^a-Z]" price.txt $5.00 #$#$ 1234556 911 11806 [root@service99 regular]# echo $LANG //在使用 [a-Z]时,注意LANG环境变量的值,该值若是进行修改的话,要注意修改的值的合法性 zh_CN.UTF-8 [root@service99 regular]# LANG=en_US.UTF-8
[root@service99 regular]# cat test.info goole go go go come on goooooooooo [root@service99 regular]# grep --color "o*" test.info goole go go go come on goooooooooo [root@service99 regular]# grep --color "go*" test.info goole go go go goooooooooo [root@service99 regular]# grep --color "w.*d" price.txt //经常与.一起使用 hello,world!
[root@service99 regular]# egrep --color "91?" price.txt This price is $4.99 911
[root@service99 regular]# egrep --color "9+" price.txt This price is $4.99 911 [root@service99 regular]# egrep --color "1+" price.txt 1234556 911 11806
[root@service99 regular]# echo "This is test,test is file." | egrep --color "test{0,1}"
This is test,test is file.
[root@service99 regular]# echo "This is test,test is file." | egrep --color "is{1,2}"
This is test,test is file.
grep --color "the" regular_express.txt
grep --color -vn "the" regular_express.txt
grep --color -in "the" regular_express.txt
grep --color -En 'test|taste' regular_express.txt
grep --color -i "t[ae]ste\{0,1\}" 1.txt
grep --color "oo" regular_express.txt
grep --color [^g]"oo" regular_express.txt grep --color "[^g]oo" regular_express.txt
egrep --color "[^a-z]oo" regular_express.txt
egrep --color [0-9] regular_express.txt
egrep --color ^the regular_express.txt
egrep --color ^[a-z] regular_express.txt
egrep --color ^[^a-Z] regular_express.txt
egrep --color $"\." regular_express.txt
egrep --color "^$" regular_express.txt
egrep --color "g..d" regular_express.txt
egrep --color "ooo*" regular_express.txt
egrep --color o\{2,\} regular_express.txt
egrep --color go\{1,\}g regular_express.txt
egrep --color [0-9] regular_express.txt
egrep --color "oo" regular_express.txt
egrep --color go\{2,5\}g regular_express.txt
egrep --color go\{2,\} regular_express.txt
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有