我已经写了一个循环来解析文件中的几行内容,并以更友好的格式提取我想要的信息,但是我得到的重复字符串是我正在解析的打印。我认为我在使用echo | sed
命令时做错了什么(而且很愚蠢),但我现在看不到它了。任何人都可以指出我要出错的地方吗?从解析循环中打印多行
文件来分析容貌(略)所示:
##################################### topd Tree0 - Tree6 #######################################
* Percentage of taxa in common: 100.0%
* Split Distance [differents/possibles]: 0.461538461538462 [ 12/26 ]
* Disagreement [ taxa disagree/all taxa ]: [ 9/16 ], New Split Distance: 0, Taxa disagree: (PAUlopT PAKU2 PAKlopT PAUU4 PLTU1 PLTU3 PLTU4 PLTcif PLTlopT)
##################################### topd Tree0 - Tree7 #######################################
* Percentage of taxa in common: 100.0%
* Split Distance [differents/possibles]: 0.538461538461538 [ 14/26 ]
* Disagreement [ taxa disagree/all taxa ]: [ 9/16 ], New Split Distance: 0, Taxa disagree: (PAKU2 PAKlopT PAUU4 PAUlopT PLTU1 PLTU2 PLTU3 PLTU4 PLTlopT)
##################################### topd Tree0 - Tree8 #######################################
* Percentage of taxa in common: 100.0%
* Split Distance [differents/possibles]: 0.230769230769231 [ 6/26 ]
* Disagreement [ taxa disagree/all taxa ]: [ 4/16 ], New Split Distance: 0, Taxa disagree: (PLTU1 PLTU2 PLTU3 PLTU4)
而且我想只是头和类群不同意(即线1和线4月底)
但我发现了这其中线三重(在某些情况下给予不同类群名单,但如果它是一个单独的一个我还没有解决这个问题至今):
Tree0 - Tree6 PAKlopT PAUlopT PLTU1 PLTU2 PLTU3 PLTU4 PLTlopT
Tree0 - Tree6 PAKlopT PAUlopT PLTU1 PLTU2 PLTU3 PLTU4 PLTlopT
Tree0 - Tree6 PAKlopT PAUlopT PLTU1 PLTU2 PLTU3 PLTU4 PLTlopT
Tree0 - Tree6 PAUlopT PAKU2 PAKlopT PAUU4 PLTU1 PLTU3 PLTU4 PLTcif PLTlopT
Tree0 - Tree6 PAUlopT PAKU2 PAKlopT PAUU4 PLTU1 PLTU3 PLTU4 PLTcif PLTlopT
Tree0 - Tree7 PAUlopT PAKU2 PAKlopT PAUU4 PLTU1 PLTU3 PLTU4 PLTcif PLTlopT
Tree0 - Tree7 PAUlopT PAKU2 PAKlopT PAUU4 PLTU1 PLTU3 PLTU4 PLTcif PLTlopT
Tree0 - Tree7 PAUlopT PAKU2 PAKlopT PAUU4 PLTU1 PLTU3 PLTU4 PLTcif PLTlopT
Tree0 - Tree7 PAKU2 PAKlopT PAUU4 PAUlopT PLTU1 PLTU2 PLTU3 PLTU4 PLTlopT
Tree0 - Tree7 PAKU2 PAKlopT PAUU4 PAUlopT PLTU1 PLTU2 PLTU3 PLTU4 PLTlopT
Tree0 - Tree8 PAKU2 PAKlopT PAUU4 PAUlopT PLTU1 PLTU2 PLTU3 PLTU4 PLTlopT
Tree0 - Tree8 PAKU2 PAKlopT PAUU4 PAUlopT PLTU1 PLTU2 PLTU3 PLTU4 PLTlopT
Tree0 - Tree8 PAKU2 PAKlopT PAUU4 PAUlopT PLTU1 PLTU2 PLTU3 PLTU4 PLTlopT
Tree0 - Tree8 PLTU1 PLTU2 PLTU3 PLTU4
Tree0 - Tree8 PLTU1 PLTU2 PLTU3 PLTU4
,这是我写的代码(I D oubt这是特别优雅或有效)
#!/bin/bash
file="$1"
###
while read LINE ;
do
if [[ $LINE == "#"* ]]
then
header=$(echo $LINE | sed 's/\#//g' | sed 's/\ topd\ //g')
fi
if [[ $LINE == "* Disagreement"* ]] ;
then
taxa=$(echo $LINE | sed 's/.*(\(\ .*\ \))/\1/' | grep "^ " |sed 's/\ /\t/g')
fi
echo "$header""$taxa"
done < $file
编辑:
我尝试过程中的实际文件: https://drive.google.com/open?id=0Bz_H3y-7pX9FX0lZTWNBdlpIQmc
我建议使用如awk文本处理语言或sed的,而不是庆典。 – 123
您的脚本中的逻辑错误:您正在为您处理的每一行打印一行。只有在处理“*不一致”行后才打印。 –