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