2013-05-06 6 views
3

awk에게 다섯 번째 필드를 기준으로 분할 할 파일의 구분 기호를 콜론 ":"또는 ":"로 구분할 수 있다는 것을 제외하고는 작은 변형 인 this을 시도하고 있습니다. 탭 \ t. 나는 awk -F '[:\t]' 부분을 혼자서한다, 맞은 $ 5 분야를 실제로 인쇄한다.

awk -F '[:\t]' ' # read the list of numbers in Tile_Number_List 
    FNR == NR { 
     num[$1] 
     next 
    } 

    # process each line of the .BAM file 
    # any lines with an "unknown" $5 will be ignored 
    $5 in num { 
     f = "Alignments_" $5 ".sam"  print > f 
    } ' Tile_Number_List.txt little.sam 

왜이 작동하지 않습니다 :이 코드

               print > f 
awk: cmd. line:9:           ^syntax error 

: 나는 더 큰 명령이 점을 통합 할 때

그러나

는, 다음과 같은 오류를 반환 -F 옵션? ; 또는 줄 바꿈으로 구분 하나, 그래서 당신은 한 줄에 두 문장이

f = "Alignments_" $5 ".sam"  print > f 

:

답변

2

문제는 FS의 값이 아니다는이 오류에 의해 지적 라인의

f = "Alignments_" $5 ".sam"; print > f 

또는 :

f = "Alignments_" $5 ".sam" 
print > f 

전체 하나 라이너로

:

BEGIN { 
    FS="[:\t]" 
} 
# read the list of numbers in Tile_Number_List 
FNR == NR { 
    num[$1] 
    next 
} 
# process each line of the .BAM file 
# any lines with an "unknown" $5 will be ignored 
$5 in num { 
    f = "Alignments_" $5 ".sam"   
    print > f 
} 

이 양식 awk -f script.awk Tile_Number_List.txt little.sam에서 실행하려면 :

awk -F '[:\t]' 'FNR==NR{n[$1];next}$5 in n{print > ("Alignments_"$5".sam")}' 

또는 스크립트 파일 즉 script.awk

.

편집 :

- 많은 * nix에서 스크립트 도구를 사용하여 파일 대신 stdin에서 입력을 표시하는 데 사용되는 문자.

command | awk -f script.awk Tile_Number_List.txt - 
+0

대단히 감사합니다. –

+0

@CarmenSandoval이 문제를 해결 한 경우이 답변을 upvote하고 동의하는 것을 잊지 않았습니다. –

+0

예, 방금 몇 분 정도 기다려야합니다 :) –

관련 문제