inux删除文件中空行的几种方法
2015-08-14 09:27
253 查看
file文件内容如下
![](http://s3.51cto.com/wyfs02/M00/71/5E/wKioL1XNPw7hLXm5AABumNMo1oc751.jpg)
一、 sed
sed '/^$/d' file #删除空行
sed '/^\s*$/d' file #删除包含有空格的空行
[root@test1 test]# cat file 1 2 The world is not you can do, but you should. o
![](http://s3.51cto.com/wyfs02/M00/71/5E/wKioL1XNPw7hLXm5AABumNMo1oc751.jpg)
一、 sed
sed '/^$/d' file #删除空行
sed '/^\s*$/d' file #删除包含有空格的空行
[root@test1 test]# sed '/^$/d' file 1 2 The world is not you can do, but you should. o [root@test1 test]# [root@test1 test]# sed '/^\s*$/d' file 1 2 The world is not you can do, but you should. o二、grep
[root@test1 test]# grep -v "^\s*$" file 1 2 The world is not you can do, but you should. o三、awk
[root@test1 test]# awk NF file 1 2 The world is not you can do, but you should. o
[root@test1 test]# awk '!/^$/' file 1 2 The world is not you can do, but you should. o 未剔除含有空格的空行 [root@test1 test]# awk '!/^[[:space:]]+/ && !/^$/' file 1 2 The world is not you can do, but you should. o 剔除了含有空格的行
相关文章推荐
- php学习-05字符串
- sync_binlog
- VS2010,C语言编程调用函数sqrt
- QTranslator的使用
- DevExpress v15.1:ASP.NET MVC功能升级(二)
- 如何使用vb通过outlook收发邮件
- hdu1301 Jungle Roads (最小生成树)
- 资源加载和页面事件 load, ready, DOMContentLoaded等
- v4l2摄像头移植mjpg_streamer笔记
- 用户体验可以从那些方面去着手
- Android应用市场App发布
- php学习-04数据类型
- Win10正式版怎么卸载IE浏览器?
- centos 7 忘记root密码修改过程
- 调优 PHP
- 飞行熊猫游戏源码android版
- SEAndroid安全机制简要介绍和学习计划
- 用spy++ 查看消息
- java.lang.IllegalArgumentException: Illegal character in query at index ...解决办法
- 高清视频:《公开课2》Tiny开源框架服务及CEP深入剖析