我想匹配後跟「ETN:」(即(name1/name2))的字符串,並且在匹配它之後,我想要在字符串「數據達到了」使用perl打印匹配的字符串
ETN: name1/name2
abchsfk/jshflka/ZN (cellLVT)
asjkfsa/sfklfkshfsf/Z (mobSVT)
asjhfdjkfd/sjfdskjfhdk/hsakfshf/Z (celLVT)
asjhdjs/jhskjds/ZN (abcSVT)
shdsjk/jhskd/ZN (xyzSVT)
name1/name2/ZN (abcLVT)
data reached
asjhfdjkfd/sjfdskjfhdk/hsakfshf/Z (celLVT)
asjkfsa/sfklfkshfsf/Z (mobSVT)
shdsjk/jhskd/ZN (xyzSVT)
asjhdjs/jhskjds/ZN (abcSVT)
shdsjk/jhskd/ZN (xyzSVT)
name1/name2/ZN (abcLVT)
ETN: name3/name4
abchsfk/jshflka/ZN (cellLVT)
asjkfsa/sfklfkshfsf/Z (mobSVT)
asjhfdjkfd/sjfdskjfhdk/hsakfshf/Z (celLVT)
asjhdjs/jhskjds/ZN (abcSVT)
shdsjk/jhskd/ZN (xyzSVT)
name3/name4/ZN (fhLVT)
data reached
asjhfdjkfd/sjfdskjfhdk/hsakfshf/Z (celLVT)
asjkfsa/sfklfkshfsf/Z (mobSVT)
shdsjk/jhskd/ZN (xyzSVT)
asjhdjs/jhskjds/ZN (abcSVT)
shdsjk/jhskd/ZN (xyzSVT)
name3/name4/ZN (fhLVT)
輸出:
name1/name2/ZN (abcLVT)
name3/name4/ZN (fhLVT)
CODE:
我試圖用ETN 3月1日的字符串,並試圖將其打印出來。
if ($line =~ m/ETN: /)
{
my @names = split//, $line;
$a = $names[3];
if ($line =~ m /$a /)
{
print " $line \n" ;
}
}
謝謝你的解釋。我試圖編寫代碼,仍在學習。你的解釋非常有用。我會努力的。 – SKG