我有一个 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
Run Code Online (Sandbox Code Playgroud)
我如何完成这里的第三步?对一般问题的更好解决方案也值得赞赏注意:此环境中没有 GUI
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
Run Code Online (Sandbox Code Playgroud)
因此你可以做
tail -n +51 myfile >>tmp
Run Code Online (Sandbox Code Playgroud)