【发布时间】:2019-11-15 15:50:57
【问题描述】:
我有 2 个输入文件。
$> cat file1.txt
! This is a comment in file1.txt
// Another comment and below line is an empty line
SIR 8
TDI(03)
TDO(01)
MASK(03);
和
$> cat file2.txt
! This is a comment in file2.txt
// Another comment and below line is an empty line
sir 8 tdi(03) tdo(01) mask(03);
现在,我正在尝试编写一个脚本来收集所有这些“先生”台词。这就是我所拥有的:
while(<>) {
# Skip over all lines that start with ! or are empty or start with //
next unless !/^!/ and !/^\s*$/ and !/^\s*\/\//;
# I'm using the modifier /i to be case insensitive
if(/sir\s+\d+\s+tdi\(\d+\)\s+tdo\(\d+\)\s+mask\(\d+\)\s*;/i) {
print $_;
}
}
现在匹配单行的 file2.txt,但不匹配多行的 file1.txt。我搜索了很多并尝试了建议的修饰符 /m /s 和 /g 但没有运气。请问你能帮我找到正确的语法吗?
【问题讨论】: