我一直试图使用单词边界grep一个确切的
shell‘变量’,
grep "\<$variable\>" file.txt
但没有成功;我已经尝试了其他一切但没有成功.
其实我是从Perl脚本调用grep:
$attrval=`/usr/bin/grep "\<$_[0]\>" $upgradetmpdir/fullConfiguration.txt`
$_ [0]和$upgradetmpdir / fullConfiguration.txt包含一些匹配的“文本”.
但操作后$attrval为空.
解决方法
@OP,你应该在Perl中做’grepping’.除非没有选择,否则不要不必要地调用系统命令.
$mysearch="pattern"; while (<>){ chomp; @s = split /\s+/; foreach my $line (@s){ if ($line eq $mysearch){ print "found: $line\n"; } } }