shell第六天

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/:被模式匹配到的行内的所有的行。
 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值