Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

9
  • Thanks. (1) From gnu.org/software/gawk/manual/html_node/String-Functions.html, b = gensub(/(.+) (.+)/, "\\2 \\1", "g", a), are \1 and \2 evaluated by the function or before calling the function? Why does it work? (2) Does substr(s[1],2) return the suffice of string s[1] starting from the second character of s[1]? Will its output include the last character ,? Commented Jul 17, 2017 at 18:01
  • \1 and \2 in the string passed to gensub will get replaced by gensub for every match. But the string passed to gensub stays otherwise fixed. In your post you try to provide an expression, but that must be converted into a string (which can contain \1) before it gets passed to gensub. The substr call is as you described, it starts from character position 2 until the end. Commented Jul 17, 2017 at 19:02
  • Thanks. I see. How would you do to "check n is 2 to ensure you got exactly one match"? Commented Jul 17, 2017 at 23:25
  • Note that if there are more than one, then it is always the last one that is what I want. Commented Jul 18, 2017 at 1:02
  • In gensub(/\/([0-9]+),/, "/" (\\1+3) ","), what will \\1+3 in the second argument become after evaluating and then what will it become after converting to string? Commented Jul 18, 2017 at 8:18