2010-12-09 4 views
0

다음은 파일의 예입니다. 여섯 번째 열 값을 파싱하여 배열에 저장하려고한다고 가정 해 봅시다.Perl에서 열의 값을 탭으로 구분 된 텍스트 파일로 저장하는 방법

use strict; 

my @arr;  
while(<>) { 
     my @tmp = split/\t/; 
     push @arr,$tmp[5]; 
} 

과 같은 스크립트를 호출 :

 
42 test.example.com activityViewer/index.html 8a699fe62751d158dad57f6b9a3ae5a4 1291836592 4.1938788890839 
4 test.example.com activityViewer/index.html ca0317343500ac35d46ca6b6bfe5918d 1291836592 4.224240064621 
38 test.example.com activityViewer/index.html 2a473f02e814896af9d20ad333dfd5c5 1291836592 4.2302849292755 
9 test.example.com activityViewer/index.html ac3942ad87fb0ce3efb034cdfc3d4c79 1291836592 4.2612450122833 
31 test.example.com activityViewer/index.html 3497d90401e18483119b60a378bd8d27 1291836592 4.3139219284058 
25 test.example.com activityViewer/index.html 377b12a86f6bbde33dc89e94cacd5246 1291836592 27.90621805191 
3 test.example.com activityViewer/index.html 493bf2ba361b77d09305a14e9253322d 1291836592 29.722389936447 

답변

5

당신은 할 수

$ perl myprg.pl file 

See it

는 다른 방법이 필드 구분자로 탭 CSV로 파일을 처리 할 수 ​​있습니다 적절한 CSV 파서 모듈을 사용하십시오.

0

Is there a Perl module for parsing columnar text?은 찾고 계신 것 같습니다.

+0

유사한 간단한 방법이 될 것입니다,하지만 난 내 예를 들어 당신이 제안 링크에 비해 실제로는 간단하다,이 "스택"열을 해달라고하지만, 덕분에 나는 또한하지 마십시오 – kamal

0

는 분할

my @ary; 
foreach my $line (split(/\n/, $full_text)) { 
    my @l = split(/\t/, $line); 
    push @ary, $l[5] 
} 
+0

보았다 빌어 먹을. –

관련 문제