Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace all UUID strings with new UUID strings

Tags:

linux

bash

uuid

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?

like image 953
timy Avatar asked Oct 31 '25 16:10

timy


1 Answers

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
like image 155
Tyilo Avatar answered Nov 02 '25 08:11

Tyilo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!