Skip to content

Instantly share code, notes, and snippets.

@mtholder
Created May 17, 2017 21:53
Show Gist options
  • Select an option

  • Save mtholder/d20bd158e45b0e9d83842d878c8404f5 to your computer and use it in GitHub Desktop.

Select an option

Save mtholder/d20bd158e45b0e9d83842d878c8404f5 to your computer and use it in GitHub Desktop.
import sys
fn = sys.argv[1]
ls_list = []
mapping = {}
with open(fn, 'r') as inp:
for n, line in enumerate(inp):
ls = line.split('\t|\t')
assert len(ls) == 5
assert ls[-1] == '\n'
if n > 0:
uid = ls[0]
name = ls[2]
assert uid not in mapping
mapping[uid] = name
ls_list.append(ls)
out = sys.stdout
for n, ls in enumerate(ls_list):
if n > 0:
ls[0] = mapping[ls[0]]
if ls[1]:
ls[1] =mapping[ls[1]]
out.write('\t|\t'.join(ls))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment