Liste des Groupes | Revenir à cl awk |
On 4/10/2025 2:09 AM, Janis Papanagnou wrote:FWIW, probably more for the benefit of any awk newcomers reading this, if your data really could have quoted fields (otherwise a simple `split(data,",")` is all you need) then, assuming they follow the same quoting rules as for CSVs, I'd use either of these or similar with GNU awk (for `patsplit()`:On 10.04.2025 09:06, Janis Papanagnou wrote:Correct, you can't do what you want using just `match()`, it's simply matching a regexp with capture groups against a string, just like sed does.I'm looking for subexpressions of regexp-matches using GNU Awk's>
third parameter of match(). For example
>
data = "R=r1,R=r2,R=r3,E=e"
match (data, /^(R=([^,]+),){2,5}E=(.+)$/, arr)
>
The result stored in 'arr' seems to be determined by the static
parenthesis structure, so with the pattern repetition {2,5} only
the last matched data in the subexpression (r3) seems to persist
in arr. - I suppose there's no cute way to achieve what I wanted?
To clarify; what I wanted is access of the values "r1", "r2", "r3",
and "e" through 'arr'.
There are, of course, several other ways to get `arr[]` populated the way you want. e.g split(), patsplit(), while(match()), or dynamically generating the regexp. The best one to choose will depend on the real values that r1, etc. can have, for example it'd be hard to use split() if `r1` can be a quoted string that might itself contain similar substrings such as `data = "R=\"R=r1,R=r2\",R=r2,R=r3,E=e"`.
Les messages affichés proviennent d'usenet.