shell腳本,當用sed刪除某一文件里面的內容時,並追加到同一個文件會出現問題。


shell腳本,當用sed刪除某一文件里面的內容時,並追加到同一個文件會出現問題。
因為初始文件和寫入文件是一個文件這是失敗的。需要追加到另一個文件,然后再用mv進行操作。
[root@localhost wyb]# seq 10 > 10.txt [root@localhost wyb]# cat 10.txt 1 2 3 4 5 6 7 8 9 10 [root@localhost wyb]# cat 10.txt |sed '1,5d' 6 7 8 9 10 [root@localhost wyb]# cat 10.txt |sed '1,5d' >10.txt [root@localhost wyb]# cat 10.txt [root@localhost wyb]# seq 10 >10.txt [root@localhost wyb]# cat 10.txt 1 2 3 4 5 6 7 8 9 10 [root@localhost wyb]# cat 10.txt |sed '1,5d' >11.txt [root@localhost wyb]# cat 11.txt 6 7 8 9 10 [root@localhost wyb]# mv 11.txt 10.txt mv: overwrite `10.txt'? y [root@localhost wyb]# cat 10.txt 6 7 8 9 10 [root@localhost wyb]#

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM