SHELL实战day4
一 正则介绍_grep
1:grep用来过滤关键词
grep [-cinvABC] 'word' filename
-c 行数 (count)
-i 不区分大小写
-n 显示行号
-v 取反
-r 遍历所有子目录
-A 后面跟数字,过滤出符合要求的行以及下面n行
-B 同上,过滤出符合要求的行以及上面n行
-C 同上,同时过滤出符合要求的行以及上下各n行
2:示例
grep -n 'root' /etc/passwd
grep -nv 'nologin' /etc/passwd
grep '[0-9]'/etc/inittab
grep -v '[0-9]'/etc/inittab
grep -v '^#' /etc/inittab
grep -v '^#' /etc/inittab|grep -v '^$'
grep '^[^a-zA-Z]' test.txt
grep 'r.o' test.txt
.表示任意一个字符
grep 'oo' test.txt
表示左边的字符重复0到n次
grep '.' test.txt
.表示任意字符
grep 'o{2}' /etc/passwd
{}表示前面字符的重复范围
egrep 'o{2}' /etc/passwd
和上面一样的效果
egrep 'o+' /etc/passwd
+符号前面字符的一次或多次
egrep 'oo?' /etc/passwd
?表示前面字符重复0或1次
egrep 'root|nologin' /etc/passwd
|表示或者的意思
egrep '(oo){2}' /etc/passwd
二 sed
1: sed -n '5'p test.txt
sed -n '1,5'p test.txt
sed -n '1,$'p test.txt
sed -n '/root/'p test.txt
sed -n '/root/'Ip test.txt
匹配大小写
sed -n '/^1/'p test.txt
sed -n 'in$'p test.txt
sed -n '/r..o/'p test.txt
sed -n 'oo*'p test.txt
sed -e '1'p -e '/111/'p -n test.txt
2: sed '1'd test.txt
sed '1,3'd test.txt
sed -i '1,3'd test.txt
删除文件内容
sed '/oot/'d test.txt
sed '1,2s/ot/to/g' test.txt
sed 's#ot#to#g' test.txt
sed 's/[0-9]//g' test.txt
sed 's/[a-zA-Z]//g' test.txt
sed -r 's/(rot)(.)(bash)/\3\2\1/' test.txt
sed 's/^.$/123&/' test.txt
sed -i 's/ot/to/g' test.txt
- SparkShell实战
- linux shell实战 笔记学习及学习之什么是shell
- 企业实战Shell-MySQL分库分表备份脚本 【转】
- Linux初学实战之shell
- 企业shell脚本分析及切割apache日志实战 推荐
- 实战Linux Shell(1):Shell简介
- 2.Spark编程模型(上)--概念及SparkShell实战
- shell实战开发
- 18道Shell高级编程企业实战题及参考答案
- Linux Shell编程实战---shell实现图片下载神器
- linux实战(十一)----shell监控服务器性能---综合运用
- Linux实战教学笔记17:精简shell基础
- Hadoop之旅(9)— Hbase 教程与shell实战操作
- 详解Shell编程之if语句实战(小结)
- Python3教程Web开发实战梳理-day4(编写Model)
- shell实战(1)
- 第一次实战shell
- Linux入职基础-5.19_详解操作shell启动(应用实战3)
- 企业shell面试题:利用Linux三剑客解答企业面试题实战