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
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