Replace Tab with Space

Replacing each <TAB> character in a file with a comma character can be accomplished several different ways with Perl. (I guess that’s one reason the Perl slogan says There’s more than one way to do it.)

My favorite way is like this, from the command-line:

perl -pi.bak -e ‘s/\t/,/g’ myfile.txt

From the Unix (or DOS) command-line, you can invoke Perl just like this to convert the file named myfile.txt. This command edits the file in place, and makes a backup file named myfile.txt.bak (in case we make an error). The new version of myfile.txt contains the changes you just made — all the characters have been converted to commas.

The command line options I used here are:

-p

Assumes an input loop around your script.

-i EXT

Files processed by the <> construct are to be edited in-place.

-e COMMANDS

May be used to entering one line of a script (or, in this case, a one-line script).