【发布时间】:2018-06-13 08:59:57
【问题描述】:
我有一个格式如下的文件:
define host{
use generic-printer
host_name imp-p-125
address 100.68.22.10
hostgroups network-printers
}
define service{
use generic-service
host_name imp-p-125
service_description Toner 1 Status
check_command check_toner1
check_interval 240
retry_interval 2
notification_interval 245
}
我正在尝试查找 host_name 行 (1imp-p-1251),目的是不重复文件中存在的主机。
我有以下代码来执行此操作,但它总是告诉我“找到”了我在键盘中输入的所有名称。
sub openFile {
open(FILE, "/home/server/test2.txt");
print "file open!\n";
print "hostname(Example 'imp-p-125'): ";
my $name = <STDIN>;
chomp $name;
if (grep{$name} <FILE>){
print "found\n";
}else{
print "word not found\n";
}
close FILE;
}
我正在搜索使用带有 STDIN 方法的 RegEx 的选项,但我找不到任何东西。
提前致谢。
【问题讨论】:
-
我认为 RegEx 或 regex 是可以接受的...RegEx 使它看起来像一个视频游戏或 ActiveX...
-
谢谢,但我还在寻求帮助!!
标签: regex string perl file stdin