-1

I tried to do specific thing using for loops and I need you help.

I have different folders that have different names like GCF_A1 GCF_C4 GCF_R3... and so on.

Every folder there's lots of files that have different names like this GCF444444 GCF00001RR GCF1000FF... and so on.

What I want to do is make all the GCF4444 files (that are in gz format, and in the different folders) in one file.

For example if I have 5 folders in each one there's a file I want to copy, then I want to have, in the end, one file that contains all of the content of the five files in the different folders.

JNevill
  • 46,980
  • 4
  • 38
  • 63
Reda
  • 449
  • 1
  • 4
  • 17
  • 1
    Hi Mejait. Can you share one of your attempts so we can see what direction you were headed. I feel like the `file` command with it's `-exec` option is probably the right direction here since it can handle recursively scanning for files with a `.gz` extension `cat`ing them together, but it would help to see your for loop attempt. – JNevill Apr 22 '20 at 14:29
  • ACtually i didn't know how to use for loop to do that , just because i used be before , i have like 72 folder , i each one there s a file , i want to make all this files in one file – Reda Apr 22 '20 at 14:50

2 Answers2

0

This will probably look something like:

 find <base_path_of_your_zips> -type f -name "*.gz" -exec cat {} \path\to\single\zippedfile.gz \;
JNevill
  • 46,980
  • 4
  • 38
  • 63
0

I'm not sure what exactly you're asking, but does this answer it?

find /path/to/parent/dir -name GCF4444 -print0 |xargs -0 cat > GCF4444.gz

This likely doesn't make any sense, but the question isn't terribly clear on what you want. This just blindly concatenates each file whose entire name is GCF4444 in whatever order they're found in. (gzip is robust and individual gzip files can be concatenated together without issue. There's a very small overhead cost to the extra headers, which you could remove by changing the end to |xargs -0 zcat |gzip -9 > GCF4444.gz)

Otherwise, perhaps you want to preserve the hierarchy:

cd /path/to/parent/dir
find . -name GCF4444 -print0 |xargs -0 tar -pcf GCF4444.tar

This will create a GCF4444.tar file at the top level of the parent directory. It will contain each GCF4444 file in the nested directory structure. I didn't use tar -z because you stated the file contents are already gzipped (the resulting file would likely be slightly larger).

Adam Katz
  • 14,455
  • 5
  • 68
  • 83
  • The directory names are something like this GCF_numbre in each one them theres a lot of files , the files i want end by genomic.fna.gz , so i want to make all the file genomic.fna.gz (in all the folder ) in one file , i hope it's clear – Reda Apr 22 '20 at 15:14
  • No, that is not clear. Please go back to the question and add more information there. We'd like to see the code you've tried as well as an example of the output. – Adam Katz Apr 22 '20 at 19:53