Skip to content

Instantly share code, notes, and snippets.

@SynCap
Last active August 24, 2019 05:04
Show Gist options
  • Save SynCap/f074bb94360635800fac144b39690117 to your computer and use it in GitHub Desktop.
Save SynCap/f074bb94360635800fac144b39690117 to your computer and use it in GitHub Desktop.
Bash find & sed to trim trailing spaces & convert indents
#!/bin/bash
# search for js, php & css files from current dir and below
# trim trailing spaces and tabs
# replace groups of 4 spaces to tab
# TODO: replace indents only, ie - only spaces at start of lines
# Problem: indentation tabs number must exact match to number of full spaces' groups
find ./ -type f -regex ".*\.\(js\|php\|css\)$" -exec sed -i -r 's/[ \g]+$//;s/^ {4}/\t/g' {} \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment