I have a text file contains some different UUID strings in it, I want to replace all the UUID strings by new different UUID strings, how can I do that easily in Bash?
Assuming the uuid format contains only hexadecimals with hyphens between them and these number of chars between each hypen: 8, 4, 4, 4, 12. I'm also assuming they are on their own line.
awk '
{
    if ($0 ~ /^[a-fA-F0-9]{8}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{12}$/)
    {
        system("uuidgen")
    }
    else
    {
        print $0
    }
}' file-with-uuids > new-file-with-uuids
# To override the old file with the new:
mv -f new-file-with-uuids file-with-uuids
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With