Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to insert contents of variable to parameter function gensub in awk, specifically instead of regular expression's parameter. Can you help me with it?

I have:

gawk '
 BEGIN {
   a = "abc15d56ef";
   b = gensub(/.*([0-9][0-9])d([0-9][0-9]).*/, "\\2 \\1", "g", a);
   print b;
 }'

output

output:56 15

I need it to be in this form, but it doesn't work:

gawk '
 BEGIN {
   a = "abc15d56ef";
   c="/.*([0-9][0-9])d([0-9][0-9]).*/";
   b = gensub(c, "\\2 \\1", "g", a);
   print b;
 }'

output

output:56 15
share|improve this question

Try:

gawk '
 BEGIN {
   a = "abc15d56ef"
   c=".*([0-9][0-9])d([0-9][0-9]).*"
   b = gensub(c, "\\2 \\1", "", a)
   print b
 }'
56 15
share|improve this answer
    
Thank you, it is OK – Mike Apr 15 '13 at 5:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.