Last active
December 8, 2016 14:05
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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