Created
October 2, 2016 23:41
-
-
Save RichardBarrell/fe611a35a43ee0fda62c607ab6257ad5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
import sys | |
try: | |
column_indexes = list(map(int, sys.argv[1:])) | |
except ValueError: | |
sys.stderr.write("Usage: python pick_csv.py 0 1 2...\n") | |
sys.exit(1) | |
if len(column_indexes) == 0: | |
sys.stderr.write("No output columns? Skipping early.\n") | |
sys.exit(0) | |
input = csv.reader(sys.stdin) | |
output = csv.writer(sys.stdout) | |
for in_row in input: | |
out_row = [] | |
for column_index in column_indexes: | |
out_row.append(in_row[column_index]) | |
output.writerow(out_row) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment