我試圖從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