使用sed grep工具过滤实例

版权声明:转载请标明出处! https://blog.csdn.net/weixin_38642130/article/details/83828515

在处理庞大数据量时,善用Linux三剑客sed grep awk,让你运维更加得心应手。
这里贴上实例,以防以后还用得到,仅供参考!

分割字符串

思路:将分割的字符替换成换行符。

$ sed \`s/[,,、;|/_;:-]/\n/g\` file > file1

去除特殊符号

思路:将特殊符号替换为空。
. [] {} 需要单独替换,不然会报错

$ sed \`s/[~·\"\'’‘“”■■▲△◆●★〓()()☆《》『』【】〖〗/Φ\*\&\^\#\@\!!\??\<\>\ ABCDEFGHIJKLMNOPQRSTUVWXYZ]//g\` file1 > file2
$ sed \`s/.//g\` file2 > file3
$ sed \`s/\[//g\` file3 > file4
$ sed \`s/\]//g\` file4 > file5
$ sed \`s/{//g\` file5 > file6
$ sed \`s/}//g\` file6 > file7

去除纯数字纯字母行

思路:grep出纯数字纯字母行,然后进行取反

$ cat file7 | grep -v ^ [0-9a-zA-Z]*$ > file8

去除空白行

思路:grep出空白行,然后进行取反

$ cat file8 | grep -v ^ [\ ]*$ > new_file

参考链接:
1、正则表达式快速入门
https://www.cnblogs.com/realcare/p/6028622.html
2、sed 字符串替换
https://www.cnblogs.com/linux-wangkun/p/5745584.html
3、grep中使用"\d"匹配数字不成功的原因
https://blog.csdn.net/yufenghyc/article/details/51078107

猜你喜欢

转载自blog.csdn.net/weixin_38642130/article/details/83828515