1、删除开头的空行
[root@centos79 test]# cat a.txt a g r e i x k like a f g liker a g r e a f g liker [root@centos79 test]# cp a.txt a.txt.bak [root@centos79 test]# sed 's/^\s*//g' a.txt -i ##清空空行中的空格和制表符 [root@centos79 test]# a=$(awk '{if($0 ~ /./){print NR}}' a.txt | head -n 1) ## 首个非空行的行号 [root@centos79 test]# echo $a 3 [root@centos79 test]# let a=a-1 [root@centos79 test]# sed 1,$(($a))d a.txt ## 删除开头的空行 a g r e i x k like a f g liker a g r e a f g liker
2、删除结尾的空行
[root@centos79 test]# a=$(awk '{if($0 ~ /./){print NR}}' a.txt | tail -n 1) [root@centos79 test]# let a=a+1 [root@centos79 test]# b=$(sed -n "$=" a.txt) [root@centos79 test]# echo $b 11 [root@centos79 test]# sed $(($a)),$(($b))d a.txt a g r e i x k like a f g liker a g r e a f g liker
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。