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
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
Also, on second thought, split will work in your case, since the first split is larger than the second. Split puts the balance of the input into the last split, so
split -l 300000 file_name
will output xaa with 300k lines and xab with 100k lines, for an input with 400k lines.
发布评论
评论(1)
另外,再想一想, split 将适用于您的情况,因为第一个 split 大于第二个 split。 Split 将输入的余额放入最后一个 split 中,因此
split -l 300000 file_name
将输出 300k 行的
xaa
和 100k 行的xab
,对于 400k 行的输入。Also, on second thought, split will work in your case, since the first split is larger than the second. Split puts the balance of the input into the last split, so
split -l 300000 file_name
will output
xaa
with 300k lines andxab
with 100k lines, for an input with 400k lines.