Variable regular expresion in awk.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Variable regular expresion in awk.
# 1  
Old 08-30-2006
Variable regular expresion in awk.

Smilie
Is there any way to use in awk a regular exprexion with a format not previusly known?
I mean something like /VAR/ ,obviously VAR is the variable exprexion.

Thak you all in advance.
# 2  
Old 08-30-2006
Do you mean this?
Code:
identifier_regexp = "[A-Za-z_][A-Za-z_0-9]+"
$0 ~ identifier_regexp

You can sprintf a complex string as an regexp or however you care to set it up....
# 3  
Old 08-30-2006
hi Jim that“s a good idea , however in gonna post an ex. to show you a clear image of what i“m trying.

I need this result:
Code:
$ echo ""|awk 'BEGIN{line="exec> ${TRAZA} 2>&1";file="/$NINN/jj/fgagfsa"}END{gsub(/TRAZA/,file,line);print line}'
exec> ${/$NINN/jj/fgagfsa} 2>&1

but i need to use this structure Smilie :
Code:
$ echo ""|awk 'BEGIN{line="exec> ${TRAZA} 2>&1";file="/$NINN/jj/fgagfsa";reg_exp=TRAZA}END{gsub(reg_exp,file,line);print line}'  
/$NINN/jj/fgagfsae/$NINN/jj/fgagfsax/$NINN/jj/fgagfsae/$NINN/jj/fgagfsac/$NINN/jj/fgagfsa>/$NINN/jj/fgagfsa /$NINN/jj/fgagfsa$/$NINN/jj/fgagfsa{/$NINN/jj/fgagfsaT/$NINN/jj/fgagfsaR/$NINN/jj/fgagfsaA/$NINN/jj/fgagfsaZ/$NINN/jj/fgagfsaA/$NINN/jj/fgagfsa}/$NINN/jj/fgagfsa /$NINN/jj/fgagfsa2/$NINN/jj/fgagfsa>/$NINN/jj/fgagfsa&/$NINN/jj/fgagfsa1/$NINN/jj/fgagfsa

Any ideas?
Thx
# 4  
Old 08-30-2006
not following the entire code, but...... you can pass shell environment variables like so:
Code:
echo ""|nawk -v traza="${TRAZA}" 'BEGIN{line="exec> " traza " 2>&1"; .......

# 5  
Old 08-31-2006
Yes I know but i was trying to do the all thing in awk.
Anyway thx mate.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Regular expression as a variable

I'm trying to use a series of regular expressions as variables but can't get it to behave properly. You can see below what I'm trying to do. Here with lowercase a-z and the same with uppercase, numbers 0-9 and again with a set of special characters, without having to type out every single... (3 Replies)
Discussion started by: 3therk1ll
3 Replies

2. Shell Programming and Scripting

passing a regex as variable to awk and using that as regular expression for search

Hi All, I have a sftp session log where I am transferring multi files by issuing "mput abc*.dat". The contents of the logfile is below - ################################################# Connecting to 10.75.112.194... Changing to: /home/dasd9x/testing1 sftp> mput abc*.dat Uploading... (7 Replies)
Discussion started by: k_bijitesh
7 Replies

3. Shell Programming and Scripting

String search using Regular Expresion

Hi, I am getting a string in the file, I want to parse the srting and extract the percentage from the string. Sample string are - ASAD112_sd12.34%adnmfk ASAsds_1.34%adnmfk ASAdf 2 sd12.34%adnmfk ASAD112_sd 12.34% adnmfk ASAD112_sd12.34% adnmfk I want to extract the numeric value... (3 Replies)
Discussion started by: meetvipin
3 Replies

4. Shell Programming and Scripting

Help on the regular expresion =~

my $hw_plf_desc = `grep hw_platform $NODE_CFG_FILE`; if($hw_plf_desc =~ /Netra X4270 X4446A M2 /) Could someone explain the use of =~ .... this works only for perl . What is the alternate for the same in shell . Could any one convert this to shell script (7 Replies)
Discussion started by: frintocf
7 Replies

5. Shell Programming and Scripting

KShell regular expresion

Hi, I would like to know if the parameter i am passing to a shell script is contain the following charachter : ASM. I belive that i should use regular expresion here. Can one help ? Bellow is the "if statment" i need to fix with the reg exp: if ; then #echo "IT IS AN RDBMS... (4 Replies)
Discussion started by: yoavbe
4 Replies

6. Shell Programming and Scripting

Regular expresion

Here's my script read number if echo $number | grep "" I want this "if" statement to return true only when numbers without letters is matched. For example 45 - true, 923 - true, r5 - false, tg/f - false and so on. In this script even a single digit number like "3" returns false. Thanks. (1 Reply)
Discussion started by: eXPlosion
1 Replies

7. Shell Programming and Scripting

AWK - compare $0 to regular expression + variable

Hi, I have this script: awk -v va=45 '$0~va{print}' flo2 That returns: "4526745 1234 " (this is the only line of the file "flo2". However, I would like to get "va" to match the begining of the line, so that is "va" is different than 45 (eg. 67, 12 ...) I would not have any output. That... (3 Replies)
Discussion started by: jolecanard
3 Replies

8. Shell Programming and Scripting

help in if expresion

Hi All, Is my script still error?? i try to running and still error?? need help (1 Reply)
Discussion started by: justbow
1 Replies

9. Shell Programming and Scripting

Awk's variable in regular expression

Anyone know how I will use awk's variable in a regular expression? This line of code of mine is working, the value PREMS should be a variable: awk '$1 ~ /PREMS/ { if(length(appldata)+2 >= length($1)) print $0; }' appldata=$APPLDATA /tmp/file.tmp The value of APPLDATA variable is PREMS. ... (2 Replies)
Discussion started by: Orbix
2 Replies

10. UNIX for Dummies Questions & Answers

regular expresion question

I receive windows files via the internet on my solaris server. Since unix doesn't handle blanks well I change the blanks to ? which works just fine. I take these files and ftp them to windows so our analysts can work with them. Recently I received a file with the following structure: ... (3 Replies)
Discussion started by: gillbates
3 Replies
Login or Register to Ask a Question