den*_*zer 93 linux shell split filesplitting
我想从特定的行号中拆分一个400k行的长日志文件.
对于这个问题,让我们这个任意数字300k.
是否有一个linux命令允许我这样做(在脚本中)?
我知道split
让我按大小或行号分割文件,但这不是我想要的.我想要一个文件中的第一个300k和第二个文件中的最后一个100k.
任何帮助,将不胜感激.谢谢!
再想一想,这将更适合超级用户或serverfault站点.
aca*_*bot 177
file_name=test.log
# set first K lines:
K=1000
# line count (N):
N=$(wc -l < $file_name)
# length of the bottom file:
L=$(( $N - $K ))
# create the top of file:
head -n $K $file_name > top_$file_name
# create bottom of file:
tail -n $L $file_name > bottom_$file_name
Run Code Online (Sandbox Code Playgroud)
此外,在第二个想法,拆分将适用于您的情况,因为第一次拆分大于第二次拆分.拆分将输入的余额放入最后一个拆分中,所以
split -l 300000 file_name
将输出xaa
300k线和xab
100k线,输入400k线.