Last active
April 2, 2022 23:58
-
-
Save jion/3244ea72d14facb3d791ed213117f5a4 to your computer and use it in GitHub Desktop.
Helper to filter CSV columns you need
This file contains 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
#!/usr/bin/python3 | |
import csv | |
import sys | |
csv_reader = csv.DictReader(sys.stdin) | |
csv_writer = csv.DictWriter(sys.stdout, fieldnames=[h for h in csv_reader.fieldnames if h in sys.argv[1:]]) | |
csv_writer.writeheader() | |
for row in csv_reader: | |
csv_writer.writerow({f: row[f] for f in sys.argv[1:]}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment