Hi, community!
I am not an expert in bash, but I am trying to collect all filenames (ls *vcf > sample)
in a file per folder by using a single command line as follow:
for file in /hosts/strains/SRR*/results/*vcf ; do ls *vcf > sample ; done
I understand *vcf
is assigned incorrectly, but I tried multiple combinations and it does not work.
Additionally I tried using find
and -exec
as:
find /home/caroca/strains/SRR*/results/ -type f -name "*nonredundant.vcf" -exec ls {} > sample \;
But I only got one big file with the entire *vcf filenames of the entire number of folders, instead, what I need is a single file per folder that includes all VCF filenames in it. I hope you could help me out. Thank you in advance.
Thank you so much for your reply, however, I got one single file containing all the filenames in the directory
/hosts/strains/
, instead I want to have a file in each/hosts/strains/SRR*/results/
containing all VCF filenames.at first sight you will need a double loop for this, fist loop all dirs and for each loop all files
Thank you for your reply. I tried:
And I don't have individual files per folder, instead, there is one file in
/hosts/strains/
where I'm running the code.indeed, because you're still writing to the same (and single) result file.
try this:
Thank you so much!! It worked!!
alternative for the 'appending' is redirecting the whole loop to a file