Last active
July 22, 2021 08:37
-
-
Save Integralist/354e1267bef43961dd678679f5823669 to your computer and use it in GitHub Desktop.
[sed replace content across multiple files] #sed #replace #global #multiple #files #bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gsed -i 's/metrics.NewWriter(/metrics.NewLegacyWriter(/' **/*.go | |
# UPDATE: glob/wildcard doesn't appear to work any more, needs to be individual file streams | |
find . -type f -name *.go -exec gsed -i 's/foo/bar/' {} \; | |
# You'll need both -e (extended regex support) and -r (allow backreferences like \1 \2 etc) for more complex examples: | |
find . -type f -name *.go -exec gsed -i -r -e 's/, ErrMissing(.+)/, NewFieldError("\1")/' {} \; | |
find . -type f -name *.go -exec gsed -i -r -e 's/(github.com\/)fastly(\/customcli\/)/\1integralist\2/' {} \; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:argdo %s/metrics.NewWriter(/metrics.NewLegacyWriter(/ge | update | |
# If I'm working with a file type (like go) that messes with the quickfix window I'll typically pipe the list of files into Vim with no vimrc set. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vim $(search "--files=*.go" "metrics\.NewWriter" ./ | cut -d ':' -f 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment