exact string match ; search and print match

I am trying to match a pattern exactly in a shell script. I have tried two methods

awk '/\<mpath${CURR_MP}\>/{print $1 $2}' multipath

 perl -ne '/\bmpath${CURR_MP}\b/ and print' /var/tmp/multipath

Both these methods require that I use the escape character. I am guessing that is why
the variable ${CURR_MP} is not printing.

Does anyone know of a way I can search the file multipath for an exact string match and then print the match and the next field. $1 $2?

thanks

Try,

awk "/\<mpath${CURR_MP}\>/{print $1 $2}" multipath

I guess you want to expand the shell variable in your awk-one-liner. So use " " instead of ' ' . " " allows to interpret the shell variables before awk/perl has a go at it.

Hope this helps.
Regards,
Gaurav.

Works like a charm! thanks

:):b:

And how it's going with assigning output to $VAR in the other thread? Did you manage to get it to work? I'm just curious bcs. you did not give any feedback...

Works like a charm, until a regular expression metacharacter occurs in CURR_MP. Just a heads up.

Regards,
Alister

Bash doesnt know regex. If there's a glob, he had had it!.

Regards,
gaurav.

I am not referring to bash. I'm referring to awk/perl. If CURR_MP contains a "." or a "*" or a "/" or a "\" or a "[" or a "]" or a "(" or a ")" or a "+" or a "?" or a .... etc ... any character that is special to that flavor or regular expression, the outcome may very well not be the desired fixed string match.

If these characters will not occur in CURR_MP, then the solution is just fine. If they can, and if they must be matched literally, the solution is useless. I'm just pointing it out in case it's an issue.

Regards,
Alister

of course.

Regards,
gaurav.