gpt4 book ai didi

linux - 使用带有数字后缀但没有开始为零的输出文件拆分文件

转载 作者:太空狗 更新时间:2023-10-29 11:12:41 28 4
gpt4 key购买 nike

假设我有一个包含 100 行的文件 temp.txt。我想分成 10 个部分。我使用以下命令

split a 1 -l 10 -d temp.txt temp_

但我得到了 temp_0、temp_1、temp_2、...、temp_9。我想要这样的输出 temp_1,temp_2,..,temp_10。

来自 man split我得到了

-d, --numeric-suffixes
use numeric suffixes instead of alphabetic

我试着用split -l 10 --suffix-length=1 --numeric-suffixes=1 Temp.txt temp_

它说 split: option '--numeric-suffixes' doesn't allow an argument

然后,我尝试使用 split -l 10 --suffix-length=1 --numeric-suffixes 1 Temp.txt temp_

它说拆分:额外的操作数temp_'`

split --version 的输出是

split (GNU coreutils) 8.4
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Torbj�rn Granlund and Richard M. Stallman.

最佳答案

I tried to use split -a 1 -l 10 -d 1 Temp.txt temp_. But it shows error split: extra operand temp_' `

-d 没有参数。它应该按照您最初尝试的方式编写;

split -a 1 -l 10 -d Temp.txt temp_

但是,暂时忘记语法变体;

您要求它将 100 行文件拆分为 10 部分,后缀长度为 1,从在 1

^- 这种情况是错误的,因为它要求命令处理 100 行并为其提供固定参数以将其限制为仅处理 90 行。

如果您愿意将允许的后缀长度扩展到 2,那么您至少会得到一个从 01 开始的统一的两位数临时文件;

split -a 1 -l 10 --numeric-suffixes=1 -d Temp.txt temp_将创建:temp_01temp_10

您实际上可以完全否定 -a-d 参数;

split -l 10 --numeric-suffixes=1 Temp.txt temp_还将创建:temp_01temp_10

如果出于某种原因这是一个固定且绝对的要求或永久解决方案(即集成到您无法控制的其他东西),并且它始终将是一个恰好 100 行的文件, 那么你总是可以分两次完成;

cat Temp.txt | head -n90 | split -a 1 -l 10 --numeric-suffixes=1 - temp_
cat Temp.txt | tail -n10 | split -a 2 -l 10 --numeric-suffixes=10 - temp_

然后你会得到 temp_1temp_10

关于linux - 使用带有数字后缀但没有开始为零的输出文件拆分文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39260770/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com