linux中如何删除文件的最后几行


1、测试数据

root@PC1:/home/test2# ls
a.txt
root@PC1:/home/test2# cat a.txt 01
02
03
04
05
06
07
08
09
10

 

2、head 实现

root@PC1:/home/test2# ls
a.txt
root@PC1:/home/test2# cat a.txt
01
02
03
04
05
06
07
08
09
10
root@PC1:/home/test2# head -n -3 a.txt ## 删除最后3行 01
02
03
04
05
06
07

 

3、sed实现

root@PC1:/home/test2# ls
a.txt
root@PC1:/home/test2# cat a.txt
01
02
03
04
05
06
07
08
09
10
root@PC1:/home/test2# tac a.txt
10
09
08
07
06
05
04
03
02
01
root@PC1:/home/test2# tac a.txt | sed '1,3d' | tac ## 删除后三行 01
02
03
04
05
06
07

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM