Search for awk pattern in unix env variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search for awk pattern in unix env variable
# 1  
Old 10-15-2009
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.

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

Code:
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.

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

gives me again the original string:
Code:
/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:
Code:
/usr/user5/WALTDB/oracle/product/10.2.0/lib32


Last edited by sdohn; 10-15-2009 at 01:25 PM..
# 2  
Old 10-15-2009
Code:
echo $SHLIB_PATH | awk -F: '{ for (a=1; a <=NF ; ++a){if ($a~/WALTDB/){print $a}} }'

# 3  
Old 10-15-2009
Quote:
Originally Posted by sidorenko
Code:
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. Smilie

brgds from

sdohn
# 4  
Old 10-15-2009
you are welcome or rather nichts zu danken Smilie
# 5  
Old 10-15-2009
Quote:
Originally Posted by sidorenko
Code:
echo $SHLIB_PATH | awk -F: '{ for (a=1; a <=NF ; ++a){if ($a~/WALTDB/){print $a}} }'

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

Code:
 
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
# 6  
Old 10-15-2009
The expression in slashes is interpreted literally, try
Code:
...if ($a ~ myvar )...

# 7  
Old 10-15-2009
Quote:
Originally Posted by sidorenko
The expression in slashes is interpreted literally, try
Code:
...if ($a ~ myvar )...

Yes so it works now for me in this way:

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

Greetings from germany
sdohn
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk -Search pattern through Variable

Hello, We have wrote shell script for multiple file name search pattern. file format: <numner>_<20180809>.txt starting with single number and ending with 8 digits number Command: awk -v string="12_1234" -v serch="^+_+$" "BEGIN{ if (string ~/serch$/) print string }" If sting matches... (4 Replies)
Discussion started by: koti_rama
4 Replies

2. UNIX for Beginners Questions & Answers

Grep/awk using a begin search pattern and end search pattern

I have this fileA TEST FILE ABC this file contains ABC; TEST FILE DGHT this file contains DGHT; TEST FILE 123 this file contains ABC, this file contains DEF, this file contains XYZ, this file contains KLM ; I want to have a fileZ that has only (begin search pattern for will be... (2 Replies)
Discussion started by: vbabz
2 Replies

3. Shell Programming and Scripting

awk variable search and line count between variable-search pattern

Input: |Running the Rsync|Sun Oct 16 22:48:01 BST 2016 |End of the Rsync|Sun Oct 16 22:49:54 BST 2016 |Running the Rsync|Sun Oct 16 22:54:01 BST 2016 |End of the Rsync|Sun Oct 16 22:55:45 BST 2016 |Running the Rsync|Sun Oct 16 23:00:02 BST 2016 |End of the Rsync|Sun Oct 16 23:01:44 BST 2016... (4 Replies)
Discussion started by: busyboy
4 Replies

4. Shell Programming and Scripting

How to search a filename stored in a variable using a pattern?

hi, i have a variable which contains some file names delimited by a single space. FNAME="s1.txt s2.lst s3.cvs s4.lst" i have another variable that contains a pattern FILE_PATTERN="*.lst" i want to take the filenames from FNAME variable and assign each file name in to an array say for... (8 Replies)
Discussion started by: Little
8 Replies

5. Shell Programming and Scripting

Awk to match a pattern and perform a search after the first pattern

Hello Guyz I have been following this forum for a while and the solutions provided are super useful. I currently have a scenario where i need to search for a pattern and start searching by keeping the first pattern as a baseline ABC DEF LMN EFG HIJ LMN OPQ In the above text i need to... (8 Replies)
Discussion started by: RickCharles
8 Replies

6. Web Development

Deny from env=env-variable Does not work

(Above from Apache docs). On my system, using: SetEnvIf User-Agent Mozilla IsBad=1 Order allow,deny Allow from all Deny from env=IsBad ...I see that environment variable is set (using phpinfo()) but the page is still served. No errors in the Apache logs. (1 Reply)
Discussion started by: gnurob
1 Replies

7. Shell Programming and Scripting

solved -gawk, search for pattern - mark the previous line as a variable?

Im trying to parse ifconfig with awk and setup a bunch of variables in one shot. But Im having trouble figuring out how to work with data in previous lines. ifconfig output: eth0 Link encap:Ethernet HWaddr 00:50:DA:10:7F:1B inet addr:10.10.10.10 Bcast:10.10.10.127 ... (0 Replies)
Discussion started by: trey85stang
0 Replies

8. Shell Programming and Scripting

search the pattern in a file and replace with variable already defined previously in csh

I want to replace a certain pattern with the variable already defined. e.g. set path_verilog = /home/priya/bin/verilogfile my file contents are : verilog new verilog is defined here verilog_path_comes I am using the below command sed 's/verilog_path_comes/'$path_verilog'/g' <filename>... (2 Replies)
Discussion started by: nehashine
2 Replies

9. Shell Programming and Scripting

How to assign the Pattern Search string as Input Variable

guys, I need to know how to assing pattern matched string as an input command variable. Here it goes' My script is something like this. ./routing.sh <Server> <enable|disable> ## This Script takes an input <Server> variable from this line of the script ## echo $1 | egrep... (1 Reply)
Discussion started by: raghunsi
1 Replies

10. Shell Programming and Scripting

awk using env variable as search argument

Hello, I have a file like was123##abcdefg abddef was123##xuzaghg agdfgg was133##CGHAKS DKGJG from the file i need to print the line after ## where the serach value is passed by an env variable called luster (which is currently set to was123): i tried using the below code but it... (7 Replies)
Discussion started by: amit1_x
7 Replies
Login or Register to Ask a Question