gpt4 book ai didi

python - 穿插两个不同文件的行

转载 作者:行者123 更新时间:2023-11-28 21:27:58 24 4
gpt4 key购买 nike

我必须完成一项简单的任务,但我不知道该怎么做而且我被赌注了。我需要每 4 行穿插两个不同文件的行:

文件 1:

1
2
3
4
5
6
7
8
9
10
11
12

文件 2:

A
B
C
D
E
F
G
H
I
J
K
L

期望的结果:

1
2
3
4
A
B
C
D
5
6
7
8
E
F
G
H
9
10
11
12
I
J
K
L

我正在寻找 sed、awk 或 python 脚本,或任何其他 bash 命令。

感谢您的宝贵时间!!

我尝试使用识别每个文件的 4 行模块的特定 python 库来完成此操作。但它不起作用,现在我试图在没有这个库的情况下做到这一点,但不知道怎么做。

import sys
from Bio import SeqIO
from Bio.Seq import Seq
from Bio.SeqRecord import SeqRecord


def main(forward,reverse):

for F, R in zip ( SeqIO.parse(forward, "fastq"), SeqIO.parse(reverse, "fastq") ):

fastq_out_F = SeqRecord( F.seq, id = F.id, description = "" )
fastq_out_F.letter_annotations["phred_quality"] = F.letter_annotations["phred_quality"]

fastq_out_R = SeqRecord( R.seq, id = R.id, description = "" )
fastq_out_R.letter_annotations["phred_quality"] = R.letter_annotations["phred_quality"]

print fastq_out_F.format("fastq"),
print fastq_out_R.format("fastq"),


if __name__ == '__main__':
main(sys.argv[1], sys.argv[2])

最佳答案

这可能对你有用:(使用 GNU sed)

sed -e 'n;n;n;R file2' -e 'R file2' -e 'R file2' -e 'R file2' file1

或使用粘贴/bash:

paste -d' ' <(paste -sd'   \n' file1) <(paste -sd'   \n' file2) | tr ' ' '\n'

或:

parallel -N4 --xapply 'printf "%s\n%s\n" {1} {2}'  :::: file1 :::: file2

关于python - 穿插两个不同文件的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9330432/

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