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.
- Show detab.pl code
- Download: detab.pl
Limitations
- This is written in Perl so needs Perl available.
- It is a command line program and would generally run on Linux or Unix.
- The program gives two methods of tab replacement. Probably you'll need to try both to see which one comes closer to how the original file was formatted when using tabs. If custom/variable tab stops are used, such as in MS Word, then the replacement of tabs in a text file won't be consistent.
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