Possible Duplicate:
perl + one line smart perl command, in place grep to match unusual characters + full match
Ai all
I need to match exactly the PARAMETER string with the following perl line:
cat file | perl -nle 'print if /\Q$ENV{PARAMETER}/'
As the following examples, showing down
I try to match: node_name
but I get all node_name combinations names from the file,
The same about 1.1.1. and ho开发者_开发知识库st_1.A etc…
how to match exactly the following PARAMETERS ? from the file , what need to change in my perl syntax in order to give the right match?
more file
param1=uplicateParam node_name
param2=a anode_name
param3=bnode_name
param4node_name
param5=1.node_name
param6=11.11.11.11
param7=1.1.1.11
param8=[1234]
param9=* * * [@]
param10=11.1.1.11
param11=host_1.A
param12=old.host_1.A
example1
PARAMETER=node_name
export PARAMETER
cat file | perl -nle 'print if /\Q$ENV{PARAMETER}/'
DuplicateParam node_name
a anode_name
bnode_name
node_name
1.node_name
Example2
PARAMETER=1.1.1.1
export PARAMETER
cat file | perl -nle 'print if /\Q$ENV{PARAMETER}/'
param7=1.1.1.11
param10=11.1.1.11
example3
PARAMETER=host_1.A
cat file | perl -nle 'print if /\Q$ENV{PARAMETER}/'
export PARAMETER
host_1.A
old.host_1.A
How can This line:
param2=a anode_name
being grepped for node_name
yield a anode_name
while this line:
param7=1.1.1.11
being grepped for 1.1.1.1
yield param7=1.1.1.11
It seems to me that either the first should yield param2=a anode_name
or the second should yield 1.1.1.11
You should try to put word boundaries (\b
) bto match exactly:
cat file | perl -nle 'print if /\b\Q$ENV{PARAMETER}\b/'
perl -nlE 'say if /\Aparam\d+=\Q$ENV{PARAMETER}\E\s*\z/' file
精彩评论