Skip to content

Instantly share code, notes, and snippets.

@orvn
Created May 27, 2021 05:29
Show Gist options
  • Save orvn/8b61850925388f0d21d1bcf13c254cd7 to your computer and use it in GitHub Desktop.
Save orvn/8b61850925388f0d21d1bcf13c254cd7 to your computer and use it in GitHub Desktop.
Sed append newline to all files that don't have one
#### Find and append a newline to all files that do not already have one
## Regular operation for most *nix
find ~/my-path/ -type f -exec sed -i -e '$a\' {} \;
## MacOS compatible sed
find ~/my-path/ -type f -exec sed -i '' -e '$a\' {} \;
## (for find commands, consider controlling the nesting level with max-depth)
## Git compatible search (assumes current working directory is a repo)
git ls-files -z | xargs sed -i -e '$a\'
## Git compatible search and MacOS compatible sed
git ls-files -z | xargs sed -i '' -e '$a\'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment