Skip to content

Instantly share code, notes, and snippets.

@cory-weller
Created June 12, 2023 19:38
Show Gist options
  • Select an option

  • Save cory-weller/58da08cf8a34992a7a666b7fd068b7e2 to your computer and use it in GitHub Desktop.

Select an option

Save cory-weller/58da08cf8a34992a7a666b7fd068b7e2 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# DETAILS: Functions by setting the field separator to a regular expression capturing ">", tab, and space.
# For each row in the file, if it is a header (begins with ">"), update the value of variable s
# to be equal to the first word in the header, and write a header line only containing that first word.
# Every line is written to a file <first_word_in_header>.fa, splitting the file into separate contigs.
awk -F "(^>|\t| )" '{if($0 ~ /^>/) {s=$2".fa"; print ">"$2 > s} else print > s}' ${inFasta}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment