在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

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...