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