linux之正则表达式&数据(文件)处理

正则表达式

目的:使用字符进行[查找,替换,删除].
工具: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:选取数据列的颜色
  1. 举例
  "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

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:将不同字节列举出来
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

初上花样年华

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值