convert txt file with mixed spaces/tabs to tabs only (where possible) [closed] convert txt file with mixed spaces/tabs to tabs only (where possible) [closed] shell shell

convert txt file with mixed spaces/tabs to tabs only (where possible) [closed]


Depending on the source language, you could try out GNU indent. It can do a large number of things relating to the indentation of source code, though it might be more complex than you need.

For example, if I give the following program to indent -di0 <inputfile>

#include <stdio.h>int main(int argc, char **argv){  int i;    int j;  for (i = 0; i < 10; i++)    {        for (j = 0; j < 10; j++)    {        printf("x");    }  }}

It will replace it with:

#include <stdio.h>int main(int argc, char **argv){    int i;    int j;    for (i = 0; i < 10; i++) {        for (j = 0; j < 10; j++) {            printf("x");        }    }}

Or, if you need something stupid simple, there is the expand/unexpand commands.


You could use a regular expression to replace N spaces by a tab charater. For example in Python:

import rere.sub('[ ]{4}', '\t', text)