Skip to main content
deleted 24 characters in body
Source Link
Rui F Ribeiro
  • 58k
  • 28
  • 156
  • 237

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

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

I need to insert contents of variable to parameter function gensub in awk, specifically instead of regular expression's parameter.

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
edited body
Source Link
jasonwryan
  • 74.8k
  • 35
  • 204
  • 230

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

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

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

I need to insert contents of variable to parameter function gensubgensub in awkawk, 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; }'

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

output:56 15

output

output:56 15

I need to haveit bo 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; }'

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

output:56 15

output

output:56 15

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:56 15

I need to have 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:56 15

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 bo 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
Source Link
Mike
  • 31
  • 1
  • 1
  • 3
Loading