Extract files with xxx_somenumber_yyyy.zzz.vcf
1
0
Entering edit mode
10.1 years ago

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 • 5.3k views
ADD COMMENT
0
Entering edit mode

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?

ADD REPLY
0
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

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

ADD REPLY
1
Entering edit mode
10.1 years ago
Ram 44k

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!

ADD COMMENT
1
Entering edit mode

It worked :) Thank you very much

ADD REPLY
0
Entering edit mode

You're very welcome, shanika.amarasinghe!

ADD REPLY

Login before adding your answer.

Traffic: 2761 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6