linux 中如何删除文件末尾的空行

 

1、001

root@PC1:/home/test2# ls
a.txt
root@PC1:/home/test2# cat a.txt
1 e d

3 w e


root@PC1:/home/test2# awk '{if($0 != "") {i = 0} else {i++}} END {print i}' a.txt    ## 统计文本末尾空行数目
2
root@PC1:/home/test2# head -n -2 a.txt           ## 删除末尾空行
1 e d

3 w e

 

posted @ 2022-06-20 14:57  小鲨鱼2018  阅读(375)  评论(0编辑  收藏  举报