【发布时间】:2020-06-12 18:15:54
【问题描述】:
我一直在尝试自学 awk 以完成以下任务,但没有取得多大成功。
我有一个包含多个文本文件的目录:
JV-01_S01_L007_R2_002_RepetitiveText_ToRemove.txt
JV-26_S48_L_RepetitiveText_ToRemove.txt
...
每个文本文件的结构如下。 数字可能会改变,但随附的文字将始终保持不变。
JV-01_S01_L007_R2_002_RepetitiveText_ToRemove.txt
4620178 reads; of these:
4620178 (100.00%) were unpaired; of these:
1226814 (26.55%) aligned 0 times
3040861 (65.82%) aligned exactly 1 time
352503 (7.63%) aligned >1 times
73.45% overall alignment rate
JV-26_S48_L_RepetitiveText_ToRemove.txt
1601831 reads; of these:
1601831 (100.00%) were unpaired; of these:
58800 (3.67%) aligned 0 times
1344724 (83.95%) aligned exactly 1 time
198307 (12.38%) aligned >1 times
96.33% overall alignment rate
对于这个目录中的每个文件,我想编译一个csv:
Sample Total_Reads Uniquely_Mapped_Reads Multi_Mapped_Reads Unmapped_Reads
JV-01_S01_L007_R2_002 4620178 3040861 352503 1226814
JV-26_S48_L 1601831 1344724 198307 58800
...
有没有什么方法可以用一个带有 awk 的 for 循环来做到这一点?我试图使用匹配功能。 例如,如果我可以在特定行中指定匹配搜索,然后从左到右搜索由任意数量的数字组成的子字符串,直到找到空格。这将获取该行感兴趣的子字符串。
类似的东西:
for file in *.txt
do
awk 'FNR == 1 {print FILENAME, match(NR==1, \d), match(NR==4, \d), match(NR==5, \d), match(NR==3, \d) } ' $file >> Names.csv
【问题讨论】: