Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Integralist/354e1267bef43961dd678679f5823669 to your computer and use it in GitHub Desktop.
Save Integralist/354e1267bef43961dd678679f5823669 to your computer and use it in GitHub Desktop.
[sed replace content across multiple files] #sed #replace #global #multiple #files #bash
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/' {} \;
: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.
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