Created
January 16, 2015 17:19
-
-
Save pontikos/cb5adbff97b3254abf4d to your computer and use it in GitHub Desktop.
Join lines of CSV file on column field number specified (starting at 0).
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 sys | |
| i=int(sys.argv[1]) | |
| d=dict() | |
| for l in sys.stdin.readlines(): | |
| l=l.strip().split(',') | |
| k=l.pop(i) | |
| d[k]=d.get(k,[])+l | |
| for k in d: | |
| print ','.join([k]+d[k]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment