Skip to content

Instantly share code, notes, and snippets.

@bruab
Created March 25, 2015 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bruab/506e9f7f61af16dd844c to your computer and use it in GitHub Desktop.
Save bruab/506e9f7f61af16dd844c to your computer and use it in GitHub Desktop.
Let's take a tab-delimited file and replace its first column with nine spaces. Let's do this ... to all tab-delimited files.
#!/usr/bin/env python3
import sys
# Check command line arg
if len(sys.argv) != 2:
sys.stderr.write("usage: replace_first_column_with_nine_spaces.py <input.tsv>\n")
sys.exit()
# Open file
with open(sys.argv[1], 'r') as infile:
for line in infile:
fields = line.split("\t")
fields[0] = " " # 9 spaces y'all
sys.stdout.write("\t".join(fields))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment