파일의 여러 줄을 구문 분석하고 더 사용자 친화적 인 형식으로 원하는 정보를 추출하는 루프를 작성했지만 구문 분석중인 문자열의 중복이 나타납니다 인쇄. 나는 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 : 라인 triplicated (다른 분류군의 목록을 제공하는 경우에, 그러나 별도의 하나라면 나는 아직 그 문제를 해결하지 않은) 곳이 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
편집 :
내가 프로세스에 노력하고있어 실제 파일 : 가장이의 언어 만이 bash
를 사용하지 않는 아마 https://drive.google.com/open?id=0Bz_H3y-7pX9FX0lZTWNBdlpIQmc
내가 AWK와 같은 텍스트 처리 언어를 사용하는 것이 좋습니다 또는 그 대신 배쉬의 나오지 것 :
는 UNIX에서 원하는 일을 할 수있는 올바른 방법은 표준 UNIX 범용 텍스트 조작 도구 AWK를 사용하는 것입니다. – 123
귀하의 스크립트에서 귀하의 논리가 잘못되었습니다 : 귀하가 처리하는 모든 라인에 대해 라인을 인쇄하고 있습니다. "* Disagreement"행을 처리 한 후에 만 인쇄하려고합니다. –