Differences
This shows you the differences between two versions of the page.
personal:portfolio:txt2csv [2008/08/11 14:18] antonello |
personal:portfolio:txt2csv [2018/06/18 15:11] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== txt2csv.py ====== | ||
- | |||
- | //A flat text to comma separated values converter// | ||
- | |||
- | txt2csv.py is a small python script that allow you to convert a flat database file (a text file where fields have a fixed column number) to a csv file where fields are identified by a separator, usually ";" | ||
- | It is tested with files up to hundreds of megabyte, and it is relatively fast.\\ | ||
- | {{: | ||
- | |||
- | To realize this conversion you need a second file containing the information on how to split your original file. This mask file will be in the form of: | ||
- | FIELD_NAME; | ||
- | (having one field for each row) | ||
- | |||
- | To run this software you need to have the python interpreter. If it is not already installed on your machine please download it from http:// | ||
- | |||
- | txt2csv.py is Free Software, released under GNU General Public Licence, version 2. | ||
- | |||
- | Bugs reports and comments are welcome to blackhole a.t. lobianco.org | ||
- | |||
- | Many thanks for using this software !\\ | ||
- | | ||
- | < | ||
- | Usage: txt2csv.py [input_file] [output_file] [mask_file] | ||
- | |||
- | input_file | ||
- | -> is a flat text datafile where fields have a fixed length | ||
- | output_file | ||
- | -> is a standard csv file | ||
- | mask_file | ||
- | -> is a text file describing how to split the fields, in the form | ||
- | FIELD_NAME; | ||
- | </ | ||
- | Example of a flat database: | ||
- | |||
- | John Smith 35 Freedom Street 10 | ||
- | Mickey | ||
- | John Jr. | ||
- | |||
- | Example of a maskfile: | ||
- | |||
- | FIRST_NAME; | ||
- | SURNAME;10 | ||
- | AGE;3 | ||
- | ADDRESS;25 | ||
- | |||
- | Resulting csv file: | ||
- | |||
- | " | ||
- | " | ||
- | " | ||