ファイルの最初のn行を上書きします。

ファイルの最初のn行を上書きします。

7GBのテキストファイルがあり、
ファイルの最初のn行(n = 50と仮定)を編集する必要があります
。次のようにしようとします。

head -n 50 myfile >> tmp
vim tmp # make necessary edits
substitute first 50 lines of myfile with the contents of tmp
rm tmp

ここで手順3をどのように実行しますか?一般的な問題に対するより良い解決策も感謝します。注:この環境にはGUIはありません。

ベストアンサー1

man tail説明する:

   -n, --lines=[+]NUM
          output the last NUM lines, instead of the last 10;
          or use -n +NUM to output starting with line NUM

したがって、あなたはできます

tail -n +51 myfile >>tmp

おすすめ記事