linux中删除文本的最后一行

 

001、

[root@pc1 test]# ls
test.txt
[root@pc1 test]# cat test.txt
1
2
3
4
5
[root@pc1 test]# sed "$d" test.txt
1
2
3
4
5
[root@pc1 test]# sed '$d' test.txt       ## sed单引号实现
1
2
3
4

 

 

002、

[root@pc1 test]# ls
test.txt
[root@pc1 test]# cat test.txt
1
2
3
4
5
[root@pc1 test]# head -n -1 test.txt     ## head 实现
1
2
3
4

 

posted @ 2022-10-24 08:36  小鲨鱼2018  阅读(1596)  评论(0编辑  收藏  举报