I've finally decided that regular expressions are not witchcraft and that I need to learn how to use them.
For your specific problem at hand, I assume you want to replace spaces with a tab character.
In Perl, you could do:
# replace four spaces with a tab, globally
$line =~ s/ /\t/g;
You can do this directly on the command line as well: perl -e 'while (<>) { $line = $_; $line =~ s/ /\t/g; print $line; }' < foo_spaces.py > foo_tabs.py
I have a gist [1] which has very slightly more comments, if you prefer. To paraphrase XKCD, there are now N+1 regex explanations, and I apologize that mine is comparatively worse than all of them. :)0: http://perldoc.perl.org/perlre.html 1: https://gist.github.com/gknoy/94c382299c4543f2e863
I didn't actually take the entire day. :)