https://github.com/timwis/slugify-headers
A python script to get database_friendly_field_names for a CSV file
https://github.com/timwis/slugify-headers
Last synced: about 2 months ago
JSON representation
A python script to get database_friendly_field_names for a CSV file
- Host: GitHub
- URL: https://github.com/timwis/slugify-headers
- Owner: timwis
- Created: 2015-11-08T19:24:27.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-11-08T20:09:50.000Z (over 9 years ago)
- Last Synced: 2025-01-25T07:11:24.408Z (3 months ago)
- Language: Python
- Size: 0 Bytes
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Slugify Headers
A python script to get database_friendly_field_names for a CSV file## Usage
Given a CSV file where the first row contains malformed headers, ie.:
```
Animal,No. of Legs, DOMESTICATED, Notes** Here
Dog, 4, true, "great pet"
Cat, 4, false, "no thx"
```Pass the file to this script via `stdin` and it will return database-friendly headers
with special characters and extra spaces removed:
```bash
$ cat data.csv | python main.py
> animal,no_of_legs,domesticated,notes_here
```For greater efficiency, just pass the first row of the CSV file:
```bash
$ head -1 data.csv | python main.py
> animal,no_of_legs,domesticated,notes_here
```To replace the header line in the original file, use silly simple posix programs:
```bash
# Get clean headers and put then in a new file
$ head -1 data.csv | python main.py > new_data.csv# Append the source file without the first row to the new file
$ tail -n+2 data.csv >> new_data.csv
```To output the headers as JSON, append the `--json` argument:
```bash
$ head -1 data.csv | python main.py --json
> ["animal", "no_of_legs", "domesticated", "notes_here"]
```