MCPcopy Index your code
hub / github.com/Automattic/go-search-replace

github.com/Automattic/go-search-replace @0.0.11

Chat with this repo
repository ↗ · DeepWiki ↗ · release 0.0.11 ↗ · + Follow
30 symbols 70 edges 4 files 1 documented · 3% updated 1d ago0.0.11 · 2025-06-19★ 1086 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Go Search Replace

Build Status

Search & replace URLs in WordPress SQL files.

cat example-from.com.sql | search-replace example-from.com example-to.com > example-to.com.sql

Overview

Migrating WordPress databases often requires replacing domain names. This is a complex operation because WordPress stores PHP serialized data, which encodes string lengths. The common method uses PHP to unserialize the data, do the search/replace, and then re-serialize the data before writing it back to the database. Here we replace strings in the SQL file and then fix the string lengths.

Considerations

Replacing strings in a SQL file can be dangerous. We have to be careful not to modify the structure of the file in a way that would corrupt the file. For this reason, we're limiting the search domain to roughly include characters that can be used in domain names. Since the most common usage for search-replace is changing domain names or switching http: to https:, this is an easy way to avoid otherwise complex issues.

Installation

From Official Releases

To install on macOS:

wget https://github.com/Automattic/go-search-replace/releases/latest/download/go-search-replace_darwin_arm64.gz
gunzip go-search-replace_darwin_arm64.gz
chmod +x go-search-replace_darwin_arm64
mv go-search-replace_darwin_arm64 /usr/local/bin/go-search-replace
go-search-replace --version

From Source

To install from source, this package requires Go.

Note the changes you need to make to your PATH and that you have to either restart your terminal or source your shell rc file.

You need to install Gox which you can install with go install github.com/mitchellh/gox@latest

Once that's installed you can install this tool with the following command: go install github.com/Automattic/go-search-replace@latest

Go is set up by convention, not configuration so your files likely live in a directory like: /Users/user/go/src/github.com/Automattic/go-search-replace

Nagivage to that directory and run make

go-search-replace will be ready for you to use. Once built you won't have to complete any of the above steps again.

Package Usage

To use it as a package in your Go project, you can install it with the following command:

go get github.com/Automattic/go-search-replace

Once you've installed the package, you can use the searchreplace package in your project. Here's an example:

package main

import (
    "fmt"
    "github.com/Automattic/go-search-replace/searchreplace"
)

func main() {
    input := []byte(`s:3:\"foo\";`)

    result := searchreplace.FixLine(&input, []*searchreplace.Replacement{
        {
            From: []byte("foo"),
            To:   []byte("Hello, Gophers!"),
        },
    })

    fmt.Println(string(*result))
}

Core symbols most depended-on inside this repo

FixLine
called by 6
searchreplace/search-replace.go
validInput
called by 3
main.go
replaceByPart
called by 3
searchreplace/search-replace.go
replaceAndFix
called by 3
searchreplace/search-replace.go
fix
called by 3
searchreplace/search-replace.go
getUnescapedBytesIfEscaped
called by 2
searchreplace/search-replace.go
unsafeGetString
called by 1
main.go
fixLineWithSerializedData
called by 1
searchreplace/search-replace.go

Shape

Function 28
Struct 2

Languages

Go100%

Modules by API surface

searchreplace/search-replace_test.go10 symbols
searchreplace/search-replace.go9 symbols
main_test.go8 symbols
main.go3 symbols

For agents

$ claude mcp add go-search-replace \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact