Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

gensub and variables as regexp and replacement

Status
Not open for further replies.

uruski

Programmer
Jan 8, 2007
1
PL
Let's say there is a file with two lines:

xxx123yyy
xxx333yyy


I want to use gensub function, when regexp pattern and replacement are kept in variables. Lets say script looks like this:

BEGIN{
pattern="/^xxx(.+)yyy$/";
output="\\1";
}

{
print gensub(pattern,output,"g",$0);
}


I'd expect to have
123
333
but in fact pattern did not match any line, and output is
xxx123yyy
xxx333yyy

Any ideas how to use pattern from a variable ?
regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top