go-replace: golang 的一个替换命令行

golang 实现的一个替换命令行工具
更新于: 2025-02-20 10:01:45

安装

# 下载好,手动安装
cd ~/Downloads
ins go-replace.darwin.amd64 go-replace

$ go-replace -h

常用

CommandDescription

go-replace -s foobar -r barfoo file1 file2

Replaces foobar to barfoo in file1 and file2

go-replace --regex -s 'foo.*' -r barfoo file1 file2

Replaces the regex foo.* to barfoo in file1 and file2

go-replace --regex --ignore-case -s 'foo.*' -r barfoo file1 file2

Replaces the regex foo.* (and ignore case) to barfoo in file1 and file2

go-replace --mode=line -s 'foobar' -r barfoo file1 file2

Replaces all lines with content foobar to barfoo (whole line) in file1 and file2

go-replace -s 'foobar' -r barfoo --path=./ --path-pattern='*.txt'

Replaces all lines with content foobar to barfoo (whole line) in *.txt files in current path