1
$\begingroup$

I have multiple .GFF files, each in a single directory per annotated whole genome, that I wish to copy into a single directory so that I can perform a core genome alignment.

However the following code does not seem to work:

for pathname in "~/ST_0075/annotations/*/*.gff"; do cp "$pathname" ~/ST_0075/alignment; done

The directory structure is the following:

Home
-ST_0075
---Annotations
-----Sample_001
----------001.gff

The goal is to copy from multiple Sample_XXX subdirectories within Annotations the XXX.gff files into another directory named alignment

$\endgroup$

1 Answer 1

3
$\begingroup$

Tinkered a bit and realized the solution did not neccistate a for loop.

mkdir ~/ST_0075/alignment; cp ~/ST_0075/annotations/*/*.gff ~/ST_0075/alignment
$\endgroup$
3
  • 3
    $\begingroup$ Exactly, and thanks for posting an answer! Note that if you're using bash, you can make it even simpler if you enable globstar. You can do: shopt -s globstar; cp ~/ST_0075/annotations/**/*.gff ~/ST_0075/alignment and that will recurse an arbitrary number of directories under annotations, so you don't need to count the exact number of */ you need. $\endgroup$
    – terdon
    Commented Jul 12, 2021 at 16:59
  • $\begingroup$ Hi @terdon, is it ** that is doing the trick? $\endgroup$
    – haci
    Commented Jul 12, 2021 at 17:52
  • 1
    $\begingroup$ Yes, try man bash | grep -A3 'globstar$' to see the details. $\endgroup$
    – terdon
    Commented Jul 12, 2021 at 17:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.