1

How can I change .txt files, separated by tab, into csv files, separated by commas, without harming the format?

I only managed to change the type from txt to csv but all data that was separated by tab, was placed in the same Excel cell.

So what I'm asking here is:

how to change tab to a comma for many files? how to then change the files from .txt to .csv?

old_man_river
  • 11
  • 1
  • 2
  • There is not a single native command available in `cmd` for such task. You could write a [tag:batch-file] to accomplish that, but be aware of cases when the field values contain commas on their own. Anyway, there is a button called "Text to Columns" in Excel (tab "Data")... – aschipfl Aug 23 '17 at 15:36

1 Answers1

1

files, separated by tab

This is named TSV format.
To convert TSV to CSV, just have to convert tabs to comma so.

You can convert-it to .tsv ans Excel will recognize-it; or use any text file editor, and do something like

FIND: \t and REPLACE BY: , as simple as that !

To do this on many files, On windows:

you can see here How to replace "/" by ";" in files *.log to *.csv using batch on windows (Sure you need to replace \t instead of / character in your case)

On linux:

sed -i 's/\t/,/g' path/to/yourFiles/*.txt

And just need to rename your files (see for example here: Rename multiple files in Unix)

NatNgs
  • 874
  • 14
  • 25