This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Extract files with xxx_somenumber_yyyy.zzz.vcf

Hi,

I need help please... :(

I created the following code to extract .vcf files from sub directories in a directory

time find /<location path>/ -name "*.vcf"\
  | xargs cp -i --target-directory /<another location path and the directory I want to save the files in>

But now I want to modify this code to extract files which have the following format

aa_13.xxx.somenumber.yyyy.zzz.vcf
aabd_45.xxx.somenumber.yyyy.zzz.vcf
djf_65.xxx.somenumber.yyyy.zzz.vcf
fdsf_5349.xxx.somenumber.yyyy.zzz.vcf
...

From directories that contain 2 vcf files which have the same name but the xxx part.

e.g.

aa_13 directory has

aa_13.xxx.somenumber.yyyy.zzz.vcf and aa_13.somenumber.yyyy.zzz.vcf

I want to get only the aa_13.xxx.somenumber.yyyy.zzz.vcf into a separate directory.

I think there is a small edition which needs to be done, reading the xxx and yyy.zzz.vcf parts... But I just can't figure it out.

Can anyone please help, or guide me to the direction I need to go?

Thanks so much in advance

xargs bash

Hi,

This looks like an interesting problem to solve. Could you please clarify if the files are in the format:

aa_13.xxx.somenumber.yyyy.zzz
aabd_45.xxx.somenumber.yyyy.zzz
djf_65.xxx.somenumber.yyyy.zzz
fdsf_5349.xxx.somenumber.yyyy.zzz

Note that I added a .vcf to the end of the filenames. Am I correct in this assumption?

Oops, Let me edit my question so it would be much clear.

They are in the below format,

aa_13.xxx.somenumber.yyyy.zzz.vcf
aabd_45.xxx.somenumber.yyyy.zzz.vcf
djf_65.xxx.somenumber.yyyy.zzz.vcf
fdsf_5349.xxx.somenumber.yyyy.zzz.vcf

etc..

Thanks for pointing that out.

and *.vcf doesn't work?

Also, is your machine a Linux machine or a Mac?

Could you also give me some details on why you think it did not work (such as files were not copied etc). I think a cp -iv would give you a verbose summary of files being copied.

Oh I see...I have completely misguided you... I'm sorry.

The problem is that one directory has two .vcf files.

E.g. aa_13 directory has

aa_13.somenumber.yyyy.zzz.vcf
aa_13.xxx.somenumber.yyyy.zzz.vcf

What I want is to extract the one with the xxx in the middle of the file name

Thank you

1 answer

From your comments, you have files such as the ones below in your aa_13 directory:

aa_13.somenumber.yyyy.zzz.vcf
aa_13.xxx.somenumber.yyyy.zzz.vcf

You'd like to pick the latter for your work.

Try this as a test run to ensure the right files are picked:

find /<location path>/ -name "*.xxx.*.vcf"

and then, if this picks the right files, modify your command so:

time find /<location path>/ -name "*.xxx.*.vcf"\
  | xargs cp -iv --target-directory /<another location path and the directory I want to save the files in>

Hope this helps!

Log in to answer this question.