【发布时间】:2015-08-07 06:34:24
【问题描述】:
我想匹配以“SLX-”开头的两行之间的所有行(包括第一行),将它们转换为逗号分隔的行,然后将它们附加到文本文件中。
原始文本文件的截断版本如下所示:
SLX-9397._TC038IV_L_FLD0214.Read1.fq.gz
Sequences: 1406295
With index: 1300537
Sufficient length: 1300501
Min index: 0
Max index: 115
0 1299240
1 71
2 1
4 1
Unique: 86490
# reads processed: 86490
# reads with at least one reported alignment: 27433 (31.72%)
# reads that failed to align: 58544 (67.69%)
# reads with alignments suppressed due to -m: 513 (0.59%)
Reported 27433 alignments to 1 output stream(s)
SLX-9397._TC044II_D_FLD0197.Read1.fq.gz
Sequences: 308905
With index: 284599
Sufficient length: 284589
Min index: 0
Max index: 114
0 284290
1 16
Unique: 32715
# reads processed: 32715
# reads with at least one reported alignment: 13114 (40.09%)
# reads that failed to align: 19327 (59.08%)
# reads with alignments suppressed due to -m: 274 (0.84%)
Reported 13114 alignments to 1 output stream(s)
SLX-9397._TC047II_D_FLD0220.Read1.fq.gz
我想红宝石会是什么样子
- 将带有 SLX- 的两行之间的所有 /n 转换为逗号
- 将原始文本文件另存为新文本文件(或者更好的是 CSV 文件。
我认为我对如何在两个特定行之间查找和替换特别有问题。
我想我可以在不使用 ruby 的情况下做到这一点,但是看到我正在尝试进入 Ruby...
【问题讨论】:
-
对于以字符“SLX”开头的行之间的每一行,我基本上想要一个逗号而不是换行符。这应该包括带有 SLX 的第一行,但不包括最后一行
-
Read the file line by line 如果一行以
SLX-开头,则开始构建一个新的逗号分隔字符串。一旦该行以SLX-开始,停止构建字符串save it into the new file,并重新开始构建输出字符串。 -
好的,但我不能做的是'如果一行以 SLX 开头- 开始构建一个新的逗号分隔字符串。一旦该行以 SLX- 开头,停止构建字符串'。