Last Updated: January 19, 2020
·
1.411K
· josefnpat

Recursively Expand Tabs to Spaces

Using the common find and the lesser known, expand, one can easily replace tabs with spaces. In this script, the current directory will be parsed, and all tabs will be replaced with two spaces.

#!/bin/sh
# Recursively expand
find . -name $1 | while read line
do
  expand --tabs=2 $line > $line.tmp
  mv $line.tmp $line

Here is an example of parsing all *.lua files recursively in /path/to/foo/. The script is located at /path/to/script/rexp.sh.

cd /path/too/foo/
/path/to/script/rexp.sh *.lua