Skip to content

Instantly share code, notes, and snippets.

@chrisramakers
Created July 15, 2011 07:27
Show Gist options
  • Select an option

  • Save chrisramakers/1084243 to your computer and use it in GitHub Desktop.

Select an option

Save chrisramakers/1084243 to your computer and use it in GitHub Desktop.
Expands the tabs on all files matching a find-command argument
#!/bin/bash
# Author: Chris Ramakers <chris@inventis.be>
# Bash script to replace all tabs with spaces through the expand shell command
# For more info on expand run "man expand"
# Special thanks to bmk on Stackoverflow
# http://stackoverflow.com/questions/6677441/run-expand-on-find-results/6683317#6683317
# This script accepts 2 arguments
# - A path where you want to run `find` against
# - a filemask for `find` to filter the resulting files
#
# For example:
# The command will recursively find all files with a .js extension in /var/www/html
# and replace any tabs with spaces in those files
# ./expand.sh /var/www/html *.js
expand_func () {
echo "Expanding $1"
expand -t 4 "$1" > "$1.tmp"
mv "$1.tmp" "$1"
}
export -f expand_func
if [ $# -lt 2 ]; then
echo -e "USAGE: ./expand.sh /var/www/html *.php"
echo -e "Warning: notice the space between the two arguments!\nThis is NOT a full path but are two separate arguments!"
else
find $1 -name $2 -exec bash -c 'expand_func {}' \;
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment