Skip to content

Instantly share code, notes, and snippets.

@chessai
Last active January 30, 2019 15:28
Show Gist options
  • Save chessai/999e4ef312e86ea77b7a2711d568d14b to your computer and use it in GitHub Desktop.
Save chessai/999e4ef312e86ea77b7a2711d568d14b to your computer and use it in GitHub Desktop.
# recursively replace all occurrences of something.
find dir -type f -name '*.hs' -print0 | \\
xargs -0 sed -i 's/Find/Replace/g'
# recursively remove all trailing whitespace
find dir -type f -print0 | \\
xargs -0 sed -i 's/[ \t]*S//'
# recursively add newlines to the end of files that don't have them.
find dir -type f -print0 | xargs -0 sed -i -e '$a\'
# recursively change a 'oldString' which are in uncommented lines with
# 'newString', but respect comments at the end of a line.
# (Haskell style comments here, not hard to change)
find dir -type f -name '*.hs' -print0 | \\
xargs -0 sed -i 's/^\([^--]*\)newString/\1oldString/'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment