Skip to content

Instantly share code, notes, and snippets.

@jknsware
Last active March 17, 2020 21:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jknsware/2b3e4aa6d66012060357288ca2c53c9f to your computer and use it in GitHub Desktop.
Save jknsware/2b3e4aa6d66012060357288ca2c53c9f to your computer and use it in GitHub Desktop.

This seems to work better:

$ grep -rl list-inactive-ecs?ref=v0.3.35 . | xargs sed -i '' 's/v0.3.35/v0.3.36/'

This one has been sketchy.

LC_ALL=C find . -type f -name '*.tfvars' -exec sed -i '' s/this/that/g {} +

Dry run

LC_ALL=C find . -type f -name '*.tfvars' -exec sed s/this/that/gp {} +

The -type f is just good practice; sed will complain if you give it a directory or so. -exec is preferred over xargs; you needn't bother with -print0 or anything. The {} + at the end means that find will append all results as arguments to one instance of the called command, instead of re-running it for each result. (One exception is when the maximal number of command-line arguments allowed by the OS is breached; in that case find will run more than one instance.)

This example is macOS specific because of the sed -i '' s...

http://sed.sourceforge.net/sed1line.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment