다음 내용이 포함된 파일이 있습니다.
Ref BBPin r:/WORK/M375FS/HMLSBLK4BIT0P0_0/LSVCC15
Impl BBPin i:/WORK/M375FS/HMLSBLK4BIT0P0_0/LSVCC15
Ref BBPin r:/WORK/HMLSBLK4BIT0P0_0/LSVCC3
Impl BBPin i:/WORK/HMLSBLK4BIT0P0_0/LSVCC3
Ref BBPin r:/WORK/HMLSBLK4BIT0P0_0/LSVSS
Impl BBPin i:/WORK/HMLSBLK4BIT0P0_0/LSVSS
Ref BBPin r:/WORK/IOP054_VINREG5_0/R0T
Impl BBPin i:/WORK/IOP054_VINREG5_0/R0T
Ref BBPin r:/WORK/IOP055_VINREG5_1/R0T
Impl BBPin i:/WORK/IOP055_VINREG5_1/R0T
그리고 내가 실행중인 코드
#!/usr/bin/perl
use warnings;
use strict;
my @words;
my $module;
my $pad;
open(my $file,'<',"file1.txt") or die $!;
OUT: while(<$file>){
chomp;
$pad =$', if($_ =~ /(.*)\//g);
@words= split('/');
OUT1: foreach my $word (@words){
if($word eq 'IOP054_VINREG5_0'){
print "Module Found \n";
$module=$word;last OUT;
}
}
}
print $module, "\n";
print ("The pad present in module is :");
print $pad, "\n";
하지만 마지막 말을 모두 보여주고 싶습니다. 이 목표를 어떻게 달성할 수 있나요? 예상 출력
HMLSBLK4BIT0P0_0
The pad present in module is LSVCC15
HMLSBLK4BIT0P0_0
The pad present in module is LSVCC3
HMLSBLK4BIT0P0_0
The pad present in module is LSVSS
IOP054_VINREG5_0
The pad present in module is R0T
IOP054_VINREG5_0
The pad present in module is R0T
내 코드는 무엇을 보여줍니까?
IOP054_VINREG5_0
The pad present in module is R0T
답변1
다른 데이터 처리가 필요하지 않으면 Perl이 필요하지 않습니다. 간단한 awk
스크립트로 충분합니다.
$ awk -F '/' '/^Ref/ { printf("%s\nThe pad present in module is %s\n", $(NF-1), $NF) }' file
HMLSBLK4BIT0P0_0
The pad present in module is LSVCC15
HMLSBLK4BIT0P0_0
The pad present in module is LSVCC3
HMLSBLK4BIT0P0_0
The pad present in module is LSVSS
IOP054_VINREG5_0
The pad present in module is R0T
IOP055_VINREG5_1
The pad present in module is R0T
이는 입력을 /
구분된 필드로 처리하고 마지막 두 필드를 각 줄을 시작하는 형식화된 텍스트 문자열로 출력합니다 Ref
.
펄 사용:
#!/usr/bin/env perl
use strict;
use warnings;
while (<>) {
/^Ref/ || next;
chomp;
my ($module, $pad) = (split('/'))[-2,-1];
printf("%s\nThe pad present in module is %s\n", $module, $pad);
}
실행하세요:
$ perl script.pl file
HMLSBLK4BIT0P0_0
The pad present in module is LSVCC15
HMLSBLK4BIT0P0_0
The pad present in module is LSVCC3
HMLSBLK4BIT0P0_0
The pad present in module is LSVSS
IOP054_VINREG5_0
The pad present in module is R0T
IOP055_VINREG5_1
The pad present in module is R0T