Skip to content

Instantly share code, notes, and snippets.

@Gumnos
Last active June 30, 2022 18:25
Show Gist options
  • Save Gumnos/3972165b937231e0f1fbb07b7e71b736 to your computer and use it in GitHub Desktop.
Save Gumnos/3972165b937231e0f1fbb07b7e71b736 to your computer and use it in GitHub Desktop.
Find UUIDs in input (stdin or files) and replace them with new UUIDs
#!/usr/bin/awk -f
function uuid(_c, _r) {
_c = "uuidgen"
_c | getline _r
close(_c)
return _r
}
BEGIN {
r = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{8}"
}
$0 ~ r {
out = ""
s = $0
while (o = match(s, r)) {
u = substr(s, RSTART, RLENGTH)
if (o > 1) {
out = out substr(s, 1, RSTART-1)
}
if (!(u in a)) {
a[u] = uuid()
}
out = out a[u]
s = substr(s, RLENGTH+1)
}
print out substr(s, RLENGTH+1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment