Skip to content

Instantly share code, notes, and snippets.

@azalea
Last active December 8, 2016 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azalea/9425036 to your computer and use it in GitHub Desktop.
Save azalea/9425036 to your computer and use it in GitHub Desktop.
Replace more than one consecutive spaces with tab in files on both Linux and Mac OS X.
#!/bin/sh
# Replace more than one consecutive spaces with tab in files on both Linux and Mac OS X.
# You need to install gnu-sed on Mac OS X for this to work.
# Usage: spaces2tab.sh [file ...]
# See also: http://azaleasays.com/2014/03/07/os-x-sed-does-not-recognize-tab-character/
if [ "$(uname -s)" == "Darwin" ] # If the system is Mac OS X
then
mysed="gsed"
else
mysed="sed"
fi
for inputfile in "$@"
do
#echo processing $inputfile
$mysed -i 's/ \+ /\t/g' "$inputfile"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment