Skip to content

Instantly share code, notes, and snippets.

@JoeGermuska
JoeGermuska / schema_maker.py
Created March 7, 2012 22:59
Example of script to make a csvkit fixed width schema from IL Board of Ed School Report Card file layouts
#!/usr/bin/env python
import sys
import csv
input_file = sys.argv[1]
r = csv.reader(open(input_file))
w = csv.writer(sys.stdout)
w.writerow(['column','start','length'])
for row in r:
try:
@JoeGermuska
JoeGermuska / csvcut
Created September 1, 2010 20:51 — forked from bycoffe/csvcut
#!/usr/bin/env python
"""
Like cut, but for CSVs. To be used from a shell command line.
Note that fields are zero-based, as opposed to 'cut' where they are 1-based.
Should use something better than getopt, but this works...
Usage:
csvcut foobar.csv
@JoeGermuska
JoeGermuska / csvcut
Created June 11, 2010 15:21 — forked from bycoffe/csvcut
#!/usr/bin/env python
"""
Like cut, but for CSVs. To be used from a shell command line.
Note that fields are zero-based, as opposed to 'cut' where they are 1-based.
Should use something better than getopt, but this works...
Usage:
csvcut foobar.csv
strfix <- function(s) {
s = gsub("(^ +)|( +$)", "", s)
s = sub("^(.*)$","\\U\\1",s, perl=TRUE)
return (s)
}
@JoeGermuska
JoeGermuska / csvcut
Created September 14, 2009 21:01 — forked from bycoffe/csvcut
#!/usr/bin/env python
"""
Like cut, but for CSVs. To be used from a shell command line.
Note that fields are zero-based, as opposed to 'cut' where they are 1-based.
Leveraged from/motivated by an example from @bycoffe
Should use something better than getopt, but this works...
@JoeGermuska
JoeGermuska / csvcut
Created September 14, 2009 17:56
Like cut, but smart about CSV quoting
#!/usr/bin/env python
"""
Like cut, but for CSVs. To be used from a shell command line.
Change row[1] to the row index to be printed. row[1] will print the second
item in the row.
Note that fields are zero-based, as opposed to 'cut' where they are 1-based.
Leveraged from/motivated by an example from @bycoffe
#!/usr/bin/env python
import json
import os, os.path
DEFAULT_PROFILE_NAME = "default.2m2"
SESSION_PATH = "Library/Application Support/Firefox/Profiles/%s/sessionstore.js"
# TODO consider generalizing the session store to open (different users, different profiles)
def session_path():
return os.path.join(os.environ['HOME'],SESSION_PATH % DEFAULT_PROFILE_NAME)