我想将 211,548,559 行文件剪切成 10 个较小的文件。因此,例如,第一个文件将具有第 1 行到第 21154856 行
我想编写一个带有 seq 的 for 循环,让我能够自动化该过程。
我尝试先创建一个函数,然后使用 seq 创建一个循环。
run_sed(){
sed -n $1p Bar08_depth_chr1.txt > Bar8_d_c1_$1.txt
}
for pos in seq 1 10 211548559
do
run_sed $pos
done
这个脚本不起作用。我相信这是因为 sed -n 1$p
中的 $1 但我不知道如何解决它
最佳答案
对于 GNU 分割
:
split -nl/10 --additional-suffix=.txt -d Bar08_depth_chr1.txt Bar8_d_c1_
这将创建 10 个名为 Bar8_d_c1_00.txt
到 Bar8_d_c1_09.txt
的文件,这些文件可能不需要重命名。
对于 MacOS 下的split
:
split -l $(( (211548559 - 9) / 10 )) Bar08_depth_chr1.txt Bar8_d_c1_
这将创建 10 个名为 Bar8_d_c1_aa
到 Bar8_d_c1_aj
的文件,可以是 renamed到您需要的名称模式。
显示的计算会导致每个文件的行数向上舍入,以避免第 11 个文件非常小。
关于bash - 使用 sed 按序列分割文件。巴什,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56315728/