A command line tool for CSV file processing
Project description
csv_conv
Instruction
This script uses state machine to fix maleformed csv file.
Usage: csv_conv.py [Options] <filename>
Options and arguments:
[-h/--help]: Show this message.
[-s]: Define sperator. Defaults to comma.
[-q]: Define text qualifier. Defaults to auto detect.
[-t]: Trim white space at the beginning and end of each field. Defaults to double quote.
[-z]: (Being constructed) Specify timezone for time fields. Defaults to server timezone. Can also be Asia/Chongqing etc.
For standard timezone names, refer to: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
[-k]: Skip errors and continue parsing following lines.
<filename>: csv file name.
Examples
cat testcase/test_case_1.csv | csv_conv
csv_conv -t testcase/test_case_1.csv
Features
Quote within Quote
Quotes should be immediated followed by seperator or line end or EOF, otherwise it's not a valid qualifier, and should be escaped. The following format should be fixed (See ../testcase/test_case_1.csv):
"What""s up!","I"m good",I"m also good,"I'm still good"","two quotes" shouldn't make any difference""
./csv_conv.py ../testcase/test_case_1.csv
"What""s up!","I""m good","I""m also good","""I'm still good""","two quotes"" shouldn't make any difference"""
Begin/End with White Space
For fields that begin/end with white space are stripped by default. Otherwise mongoimport type conversion wouldn't work properly (See ../testcase/test_case_2.csv):
red, yellow,green ,"red "
./csv_conv.py ../testcase/test_case_2.csv
"red","yellow","green","red"
If it's not expected behavior, use -t false to cancel it.
Customize Seperator
Seperator can be customized, not necessarily to be ",". Specify seperator by -s. Note that seperators like | needs to be escaped in bash. E.g. (See ../testcase/test_case_3.csv):
"hello"||"This is a test"||"This should be good.||"||""
./csv_conv.py -s '||' ../testcase/test_case_3.csv
"hello","This is a test","This should be good.||""",
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file csv_fix-0.2.0.tar.gz.
File metadata
- Download URL: csv_fix-0.2.0.tar.gz
- Upload date:
- Size: 10.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
35ebef86e989556cf42f82ff6c0aea331a1d8466241dd4372d692b2f6eb68bc8
|
|
| MD5 |
e14012cbfe3c5988f0561eeb7682737b
|
|
| BLAKE2b-256 |
2afcf8b827c18b7052c65a472e6178cc44c8a43618b48d5542f912e3457a3e0b
|
Provenance
The following attestation bundles were made for csv_fix-0.2.0.tar.gz:
Publisher:
publish.yml on zhangyaoxing/csv_fix
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
csv_fix-0.2.0.tar.gz -
Subject digest:
35ebef86e989556cf42f82ff6c0aea331a1d8466241dd4372d692b2f6eb68bc8 - Sigstore transparency entry: 815090636
- Sigstore integration time:
-
Permalink:
zhangyaoxing/csv_fix@6d27e04254b24547653085fb7a82d54451ac2f14 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/zhangyaoxing
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6d27e04254b24547653085fb7a82d54451ac2f14 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file csv_fix-0.2.0-py3-none-any.whl.
File metadata
- Download URL: csv_fix-0.2.0-py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
294ef60129d52fc29ec87c62099a7e266908cd1dec24780de715e139c97d0f6c
|
|
| MD5 |
7fa51d0a05483c660108fd87f06007d4
|
|
| BLAKE2b-256 |
3e4164a15dbd3d958fc0746a6718f3eb874ee4f5a7552ed4fa861eff93c9fdd7
|
Provenance
The following attestation bundles were made for csv_fix-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on zhangyaoxing/csv_fix
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
csv_fix-0.2.0-py3-none-any.whl -
Subject digest:
294ef60129d52fc29ec87c62099a7e266908cd1dec24780de715e139c97d0f6c - Sigstore transparency entry: 815090642
- Sigstore integration time:
-
Permalink:
zhangyaoxing/csv_fix@6d27e04254b24547653085fb7a82d54451ac2f14 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/zhangyaoxing
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6d27e04254b24547653085fb7a82d54451ac2f14 -
Trigger Event:
workflow_dispatch
-
Statement type: