detab -- convert tabs to spaces two different ways


detab.pl is a perl program which detabs a text file using two different methods for converting tabs to spaces: 1) a column-based mode which attempts to insert spaces to a "virtual" tab location or 2) a literal number of spaces per tab character. It is especially helpful when receiving text files from collaborators who use different editors or tab settings. It is also good when you get a file with mixed tabs and spaces that cause inconsistent indentation. It's ideal for prepping source code, data files, or documentation for printing, diffing, or formatting clarity.

Limitations

This utility is part of my collection of text-processing tools.

Example

For example, if you have text like
"Test[tab]some stuff"
then with 8 chars per tab, in column mode, you'll get
"Test^^^some stuff"
             ^
    column 8

...but in literal mode, you'll get
"Test^^^^^^^^some stuff"
        8 spaces


Back to Kent's Perl Page

Last-modified: Thu Sep 11 15:46:01 EDT 2025