Search for awk pattern in unix env variable

For a Script I need to detemine which field of the unix environment variable SHLIB_PATH has the
WALTDB entry.

export SHLIB_PATH=/usr/user5/WALTDB/oracle/product/10.2.0/lib32:/usr/TZD/bin.wdad/mug/oracle/lib:
echo $SHLIB_PATH | awk -F: '{ print $1 }'

Shure gives me the first entry, but maybe it can be the second entry in all of the fields.

What I want is to split the line with the : entries and search for the string WALTDB.

echo $SHLIB_PATH | awk -F":" '{/P1VPMHAM/;print}'

gives me again the original string:

/usr/user5/WALTDB/oracle/product/10.2.0/lib32:/usr/TZD/bin.wdad/mug/oracle/lib:

Howto give a search pattern to awk what in result should only print:

/usr/user5/WALTDB/oracle/product/10.2.0/lib32
echo $SHLIB_PATH | awk -F: '{ for (a=1; a <=NF ; ++a){if ($a~/WALTDB/){print $a}} }'

Thanks user sidorenko thas was exactly what I'm looking for. :slight_smile:

brgds from

sdohn

you are welcome or rather nichts zu danken :slight_smile:

So I'm a step further now. But what if the Keyword to search for is another environment variable like:

 
SHLIB_PATH=/usr/user5/WALTDB/oracle/product/10.2.0/lib32:/usr/TZD/bin.wdad/mug/oracle/lib: ; export SHLIB_PATH
ORACLE_SID="WALTDB" ; export ORACLE_SID

echo $SHLIB_PATH | awk -v myvar=$ORACLE_SID -F: '{ for (a=1; a <=NF ; ++a){if ($a~/myvar/){print $a}} }'

The myvar assigned variable seemes not to function in this case.

regards, sdohn

The expression in slashes is interpreted literally, try

...if ($a ~ myvar )...

Yes so it works now for me in this way:

 
echo $SHLIB_PATH | awk -v Search=$ORACLE_SID -F: '{ for (a=1; a <=NF ; ++a){if ($a ~ Search){print $a}} }'

Greetings from germany
sdohn