#!/usr/bin/env ruby # frozen_string_literal: true # give a replacement version of a file replacing found UUIDs, # preserving multiple instances that might indicate relations require 'active_support/all' require 'pry' file_path = $ARGV.first abort 'Specify the file to replace' unless file_path.present? matcher = /[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/ content = File.read(file_path) puts '==== Old content ====' puts content puts "--------------------------\n\n" uuids = content.scan(matcher).uniq uuids.each do |uuid| content.gsub! uuid, SecureRandom.uuid end puts '==== New content ====' puts content