如何解决在Linux中使用split功能将多个输入文件拆分为多个输出
我有8个文件,每个文件想分成5个块。我通常会单独执行此操作,但希望将其作为循环运行。我在HPC中工作。
我创建了一个文件名列表,并将其标记为“ variantlist.txt”。我的代码是:
<div class="example-wrapper">
<p>T-shirt size:</p>
<kendo-dropdownlist [data]="listItems"
[popupSettings]="{
popupClass:'[border-round]'
}">
</kendo-dropdownlist>
</div>
但是,它仅在variantlist.txt文件中分割最终文件,仅从最终条目中输出5个块。
即使我单独列出文件:
.border-round
{
border-radius:20px;
}
它仍然仅将最终文件分成5个块。
不知道我在哪里错了。所需的输出将是40个块,每个染色体5个。您的帮助将不胜感激。
非常感谢
解决方法
使用split
时,-n
的宽度将确定将序号分割为...的输出文件的数量。
您需要-l
作为所需的行数,在您的情况下为5:
split -l 5 ${f}
,
拆分将每次创建相同的文件集并覆盖先前的文件。这是一种解决方法-
for f in $(<variantlist.txt) # don't use cat
do mkdir -p $f.split # make a subdir for the files
( cd $f.split && # change into the subdir only in a subshell
split ../$f -n 5 -d # split from there
) # close the subshell,parent still in base dir
done
或者您可以这样做-
while read f # grab each filename
do split $f -n 5 -d # split it
for x in x?? # for each split file
do mv $x $f.$x # rename it to include the parent file name
done
done < variantlist.txt # take names from this file
这要慢很多,但是不使用子目录。
我最喜欢的-
xargs -I {} split {} -n 5 -d {} < variantlist.txt
最后一个参数成为split
的前缀,而不是默认的x
。
编辑-每个文件包含20亿行,请使用以下内容:
for f in $(<variantlist.txt)
do split "$f" -d -n 5 "$f" & # run all in background at the same time
done
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。