我试图从somefile
获得前4行,并将它们与someotherfile
的内容连接并将其输出到somefile
。如何连接两个文件并将结果写回其中一个原始文件
head -4 /somefile | cat - /someotherfile > /somefile
当我做到这一点someotherfile
的内容somefile
结束了,但不是第4行。如果我输出到一个完全不同的文件,那么它效果很好。
显然有一个问题,试图写入我正在阅读的同一个文件。完成这项任务最简单的方法是什么?
我正在尝试在RedHat Enterprise 6 bash shell上执行此操作。
'head -4/somefile | cat -/someotherfile>/yetanotherfile && mv/yetanotherfile/somefile' – ooga 2014-10-29 22:49:53