Created
September 30, 2012 19:09
-
-
Save asimzeeshan/3808172 to your computer and use it in GitHub Desktop.
Eight Ways to Convert Tabs to Spaces
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
# Eight Ways to Convert Tabs to Spaces | |
# URL: http://mlawire.blogspot.com/2009/07/convert-tabs-to-spaces.html | |
# A collection of various ways to convert tabs to spaces in Unix/Linux with standard programs and utilities. | |
#1 expand/unexpand utilities | |
expand < input.txt > output.txt | |
#2 Sed | |
sed 's/\t/ /g' < input.txt > output.txt | |
#3 Awk | |
awk '{ gsub(/\t/, " "); print }' < input.txt > output.txt | |
#4 Perl | |
perl -pe 's/\t/ /g' < input.txt > output.txt | |
#5 Ruby | |
ruby -pe '$_.gsub!(/\t/, " ")' < input.txt > output.txt | |
#6a Vim editor | |
:set expandtab | |
:%retab! | |
#6b Vim editor | |
:%s/\t/ /g | |
#7 Emacs editor | |
Set 'indent-tabs-mode' to nil to have tabs automatically converted to spaces. | |
To convert a region, "M-x untabify" will change tabs to spaces and "M-x tabify" will do the inverse. | |
#8 cut | |
cut -f1- --output-delimiter=' ' < input.txt > output.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment