Dein "gensub" ersetzt "ab minimal 1 und maximal 6 Zeichen vor dem letzten
Nicht-Leerzeichen bis zum Ende" durch "die gefundenen Zeichen". Das
Ergebnis ist dann natürlich "alles vor den gefunden Zeichen" und "die
gefunden Zeichen". Wenn du nur "die gefunden Zeichen" haben willst, muss
dein RegEx den _ganzen_ String von Anfang an matchen:

print gensub("^.*(.{,6})\\>\\s*$", "\\1", "g", sInput)


Oder dieses Script für die Gesamtaufgabe:

--- script ---
#!/usr/bin/awk -f

function randonoise(c)
{
  sub(/^[0-9]$/, sprintf("%c", int(rand() * 10) + 48), c);
  sub(/^[A-Z]$/, sprintf("%c", int(rand() * 26) + 65), c);
  sub(/^[a-z]$/, sprintf("%c", int(rand() * 26) + 97), c);

  return c;
}

{
  idx = match($0, /.{,6}\>\s*$/);    # find position of first of at most 6
trailing characters at the end of the last word with optional tangling
white space
  out = substr($0, 1, idx);    # initialize output to everything before the
match

  while (idx++ < length($0))    # loop over the remaining characters
    out = out randonoise(substr($0, idx, 1));    # randonoise each
character and append to out

  print out;
}
--- /script ---
_______________________________________________
Lug-dd maillist  -  [email protected]
https://ssl.schlittermann.de/mailman/listinfo/lug-dd

Antwort per Email an