正则表达式
目的:使用字符进行[查找,替换,删除].
工具:vi,sed,awk.
alnum-英文大小写及字符和数字
alpha:英文大小写字符
blank:空格键与tab键
cntrl:控制键盘
digit:数字0-9
graph:所有按键
lower:小写字母
print:被打印的字符
punct:标点字符
upper:大写字符
space:空白字符,如:空格键,Tab
xdigit:十六进制的数字类型
grep-查找
grep -A -B --color=auto 查找字符 filename
-A:后面加数字为after,指定出后面N行信息
-B:后面加数字为befer,指定出前面N行信息
--color=auto:选取数据列的颜色
- 举例
"Open Source" is a good mechanism to develop programs.
apple is my favorite food.
Football game is not use feet only.
this dress doesn't fit me.
However, this dress is about $ 3183 dollars.
GNU is free air not free beer.
Her hair is very beauty.
I can't finish the test.
Oh! The soup taste good.
motorcycle is cheap than car.
This window is clear.
the symbol '*' is represented as start.
Oh! My god!
The gd software is a library for drafting programs.
You are the best is mean you are the no. 1.
The world <Happy> is the same with "glad".
I like dog.
google is the best tools for search keyword.
goooooogle yes!
go! go! Let's go.
# I am
a.查询关于'the'的字符
grep -n 'the' [文件名]
b.查询关于'the'的字符-不区分大小写
grep -in 'the' [文件名]
c.查询关于'test'或'taste'的字符-不区分大小写
思路:共同点t&st
grep -n 't[ae]st' [文件名]
d.查询字符'oo'
grep -n 'oo' [文件名]
e.查询数据oo不出现小写字符
grep -n '[^a-z]oo' [文件名]
f.查询数据为数字与英文
grep -n '[0-9]' [文件名]
g.得到数据有序排列
grep -n '[^[:lower:]]oo' [文件名]
h.将查询数据在查询结果首行首列
grep -n '^the' [文件名]
i.列出查询数据开头为小写的字符
grep -n '^[a-z]' [文件名]
j.列出查询数据舍弃英文字母
grep -n '^[^a-zA-Z]' [文件名]
k.列出查询数据为行尾结束为.的数据
grep -n '\.$' [文件名]
l.windows字符转换打印行数据
cat -An [文件名] | head -n -10 | tail -n 6
m.查询空白行数据
grep -n '^$' [文件名]
n.查询数据中运行的脚本
cat -n [脚本目录]
o.查询出特殊字符‘g??d’
grep -n 'g...d' [文件名]
p.查询‘ooo*’字符
grep -n 'ooo*' [文件名]
sed工具
sed-目的:将数据进行替换,删除,新增,选取.
sed [-nefr] [操作]
格式化打印:printf
printf '打印格式' 实际内容
a-警告声音输出
b-退格键
f-清除屏幕
n-输出新的一行
r-回车键
t-水平按键
v-垂直按键
xNN-数字转为字符
awk:数据处理工具
awk ‘条件类型1{操作1}’ filename
文件对比工具ASCII
diff-ASCII
目的:同一个文件(软件)的新旧版本的差异,利用ASCII对比
mkdir -p [先建立测试用的目录]
diff [-bBi] from-file to-file
from-file:原始文件名称
to-file:对比文件名称
-bBi:忽略大小写以及空白文件名称
举例:
/tmp/etstpw内的passwd.old与passwd.new制作补丁文件
diff -Naur passwd.old passwd.new>passwd.patch
cmp-bit
目的:同一个文件(软件)的新旧版本的差异,利用bit对比
cmp -l file1 file2
-l:将不同字节列举出来