1.04101802001-04101802043正则表达式匹配
egrep *^041018020(0[0-9]|[1-3[0-9]|4[0-3])$*
2.ipv4地址,邮箱地址,8位强密码,url正则表达式
ipv4地址:
(?<=(\\b|\\D))(((\d{1,2})|(1\d{2})|(2[0-4]\d)|(25[0-5]))\.){3}((\d{1,2})|(1\d{2})|(2[0-4]\d)|(25[0-5]))(?=(\\b|\\D))
郵箱地址:
^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$
8位强密码:
var reg = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,}$/;
url正则表达式:
http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?
3.sed命令使用:
地址定界和编辑命令的使用:
#: d命令
4、删除test.txt 的15行以及以后所有行;
[root@localhost ~]# sed -i '15,$d' test.txt
[root@localhost ~]# sed -e '15,$d' test.txt(只会在命令行删除,不会真的删除原文件内容)等
同于[root@localhost ~]# sed '15,$d' passwd
i \text命令
i \text:insert,表示在匹配到的行之前追加内容
[root@localhost ~]# sed -i '15,$d' test.txt
c \text命令
c \text:change,表示把匹配到的行和给定的文本进行交换
#,#: p命令
1、把/etc/passwd 复制到/root/test.txt,用sed打印所有行;
[root@localhost ~]# sed -n '1,$p' test.txt
[root@localhost ~]# sed -n p test.txt
2、打印test.txt的3到10行;
[root@localhost ~]# sed -n '3,10'p test.txt
3、打印test.txt 中包含’root’的行;
[root@localhost ~]# sed -n '/root/p' test.txt
#~#: s/pattern/string
6、替换test.txt 中’root’为’toor’;
[root@localhost ~]# sed 's/root/toor/g' test.txt
#,+N: s/pattern/string/g
替换test.txt中’/sbin/nologin’为’/bin/login’;
[root@localhost ~]# sed 's
#/sbin/nologin
#/bin/login
#' test.txt
#,~N: d命令
$:d命令
4、删除test.txt 的15行以及以后所有行;
[root@localhost ~]# sed -i '15,$d' test.txt
[root@localhost ~]# sed -e '15,$d' test.txt(只会在命令行删除,不会真的删除原文件内容)等
同于[root@localhost ~]# sed '15,$d' passwd
/regexp/ : a \text
addr1,+N:指定行以及以后的N行;
addr1,~N:指定行开始的N行;
#,/regexp/ : s/pattern/string/g
/regexp/:表示能够被regexp匹配到的行; regexp即基于正则表达式的匹配;
/regexp/, /regexp/: s/pattern/string/g
addr1,addr2:指定范围内的所有的行(范围选定);
常用地址定界表示方式:
a)0,/regexp/:从起始行开始到第一次能够被regexp匹配到的行。
b)/regexp/,/regexp/:被模式匹配到的行内的所有的行。