I want to convert a tab-separated file into a CSV file. Can anyone help me?
Select one or more lines you want to convert, or simply press Ctrl+A to select all lines. Open the File menu and choose 'Save Selected Items', or simply press Ctrl+S. From the 'Save as type' combo-box select 'Comma Delimited Text File' and ,choose or type the filename to save, and then click the 'Save' button.
You can convert an Excel worksheet to a text file by using the Save As command. Go to File > Save As. Click Browse. In the Save As dialog box, under Save as type box, choose the text file format for the worksheet; for example, click Text (Tab delimited) or CSV (Comma delimited).
TSV file can be converted into CSV file by reading one line of data at a time from TSV and replacing tab with comma using re library and writing into CSV file. We first open the TSV file from which we read data and then open the CSV file in which we write data. We read data line by line.
The answer for OSX is different.
MacOS does not understand \t
in the sed
expression.
You have to insert the tab literal into the sed search pattern by using ctrl+v then tab (see How can I insert a tab character with sed on OS X?)
sed 's/ /,/g' input_file > output_file
You can use sed as:
sed 's/\t/,/g' input_file > output_file
This will keep the input file unchanged and will create a new file output_file
with the changes.
If you want to change the input file itself without creating a new file you can use -i
option to sed to do inplace changes:
sed -i 's/\t/,/g' input_file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With