Skip to content

Instantly share code, notes, and snippets.

@sahilseth
Created November 3, 2015 18:28
Show Gist options
  • Save sahilseth/f91553f6f617f91363e7 to your computer and use it in GitHub Desktop.
Save sahilseth/f91553f6f617f91363e7 to your computer and use it in GitHub Desktop.
Adding chr to a GTF file
awk '{ if($1 !~ /^#/){print "chr"$0} else{print $0} }' Homo_sapiens.GRCh37.75.gtf
@junjieahaha
Copy link

Thanks.It worked.

@alexlenail
Copy link

This will add chr in front of every line, irrespective of what's on that line, though....

@whappycoffee
Copy link

Thank you!

@diazdc
Copy link

diazdc commented Jan 31, 2019

Thanks. For avoiding non-chromosomal regions, like repeats or mitochondrial, I just added an "or" (pipe) [A-Z ] to the regex:
/^#|[A-Z]/
These regions usually start with a capital letter instead of a number.

@aseetharam
Copy link

X and Y would be excluded with that. Instead, you can use this:

awk '{ if($1 ~ /^[0-9]+$/ || $1 ~ /^(X|Y)$/){print "chr"$0} else{print $0} }' yourfile.gtf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment