vim编辑器:
1. 默认模式(编辑模式)
1) 复制粘贴还原
nyy p P u . dd ndd
2) 定位
gg 1G G nG
3) 查找
/字符 n N
4) 替换
: 1,3 s/old/new/gic
: % s/old/new/gic
: 1,$ s/old/new/gic
2. 插入模式
i o a
I O A
3. 命令模式
:w :q :q! :wq :x :e! :! 命令
:r 文件路径 : 1,3 w
4. 打开的几种方式
vim [-r] 文件名
vim [+] 文件名
grep 行过滤
aabb
aa bb
after before
cat 文件名 | grep [选项] '关键字'
grep [选项] '关键字' 文件名
egrep '([A-Z]|[0-9])'
egrep '[A-Z0-9]'
word 匹配指定字符串(word)的值
^word 匹配以指定字符串开头的值 grep -n '^#' test.txt
word$ 匹配以指定字符串结尾的值 grep -n '!$' test.txt
[abc] 匹配中括号中的任意一个字符,它们之间是或者关系 grep -n 'g[ld]' test.txt
[^list] 匹配不在中括号中指定的任意字符 grep -n 'oo[^t]' test.txt
[n1-n2] 匹配列出的选取范围!grep -n '[A-Z]' test.txt grep -n '[a-z]' test.txt grep -n '[0-9]' test.txt
. 匹配任意一个字符 grep -n 'e.e' test.txt
\ 转义字符,将特殊符号的特殊意义去除 grep –n '\.' test.txt
x|y 管道,表示或者关系 egrep 'ab|bc'
() 表示字符串分组 egrep '^a(b|c)$'
* 量词,匹配指定内容 零次或无穷次 grep -n 'ess*' test.txt
? 量词,匹配指定内容 零次或一次 egrep -n 'ess?' test.txt
+ 量词,匹配指定内容 一次或多次 egrep -n 'ess+' test.txt
{n} 量词:匹配指定内容 n次 grep -n 'go{2}g' test.txt,使用egrep 可以不用转义
{n,m} 量词:匹配指定内容 n次到m次 grep -n 'go{2,3}g' test.txt
{n,} 量词:匹配指定内容 n次到无穷次 grep -n 'go{2,}g' test.txt