fastest way convert tab-delimited file to csv in linux

csv, linux

Solution

If all you need to do is translate all tab characters to comma characters, `tr` is probably the way to go.

The blank space here is a literal tab:

$ echo "hello   world" | tr "\\t" ","
hello,world

Of course, if you have embedded tabs inside string literals in the file, this will incorrectly translate those as well; but embedded literal tabs would be fairly uncommon.

Problem

I have a tab-delimited file that has over 200 million lines. What's the fastest way in linux to convert this to a csv file? This file does have multiple lines of header information which I'll need to strip out down the road, but the number of lines of header is known. I have seen suggestions for `sed` and `gawk`, but I wonder if there is a "preferred" choice. Just to clarify, there are no embedded tabs in this file.

Original source

Related problems