Hello netlanders,
is there a faster POSIX awk function solving task SEPSPLIT below?
task SEPSPLIT
searched:
function sepsplit(re, a, s) in POSIX awk with:
s is split into the fields a[0], a[2], ...,a[2n] by the field separator
regex re and a[2*i+1] is the string matched by re between a[2*i] and
a[2*i+2] for i = 0, 1, ..., n - 1. sepsplit() returns n.
solution:
function sepsplit(re, a, s, suffix, m) {
m = 0
suffix = s
while (match(suffix, re)) {
a[m++] = substr(suffix, 1, RSTART - 1)
a[m++] = substr(suffix, RSTART, RLENGTH)
suffix = substr(suffix, RSTART + RLENGTH)
}
a[m] = suffix
return m / 2
}
remark:
there is also gawk solution with gensub() and index() possible.
Any useful answer is appreciated.
Regards,
Steffen "goedel" Schuler


|