Score:0

PHP Serialize AWK command speed up?

cn flag

I've built an SQL migration script that will replace text in a MySQL dump file. Replacements would be easy with sed, but we must account for special serializations (PHP Serialize). The code below works but the awk command is very expensive. With a quick google search, I see many developers with the same runtime performance issues. This article breaks down how simple changes can make a large difference. If anyone knows how I can speed this command up, or faster alternatives, that would be amazing :)

#!/usr/bin/env bash

set -e

SQL_FILE="$1"

maindomain="$2"

localdomain="$3"

sed 's/;s:/;\ns:/g' "$SQL_FILE" | \
  awk -F'"' '/s:.+'$maindomain'/ {sub("'$maindomain'", "'$localdomain'"); n=length($2)-1; sub(/:[[:digit:]]+:/, ":" n ":")} 1' | \
  sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/ /g' | \
  sed "s/$maindomain/$localdomain/g" > "$SQL_FILE.txt"

rm "$SQL_FILE"

mv "$SQL_FILE.txt" "$SQL_FILE"
Score:0
cn flag

My issue faced above was solved by updating the libraries behind awk on (MacOS 12.6 (21G115)). After running brew install cgrep and brew install gawk the awk -F'"' '/s:.+'$maindomain'/ {sub(... command shown in the problem statement above saw dramatic improvements. From 3-5 minutes to ~ sys 0m0.039s.

I did not need to change the awk command to cgrep or gawk.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.