Sponsored Content
Top Forums Shell Programming and Scripting Search for specific file type in subdirectory with multiple folders Post 302981793 by cmccabe on Monday 19th of September 2016 03:37:45 PM
Old 09-19-2016
Search for specific file type in subdirectory with multiple folders

I have a directory that is in the below order (the --- is not part of the directory tree, only there to help illustrate:
Code:
DATE      --- main level
Folder1   --- level under DATE
plugin_out  --- level under Folder1
variantCaller_out.40   --- level under plugin_out
001,002,003  --- level under variantCaller_out.40

The bash below reads each line in out.txt and uses that in a below. So for this example a would be /home/cmccabe/nfs/exportedReports/Folder1. What I am having trouble with is the vcf.gz being searched for is two more levels down (last level in the above). /home/cmccabe/nfs/exportedReports/plugin_out/variantCaller_out.40/001. The level right before that /home/cmccabe/nfs/exportedReports/plugin_out/variantCaller_out.40 is consistent unitil the ., then the numbers varies. So in this example variantCaller_out.40 the portion in bold will change. The last level has 3 folders 001, 002, 003 that the vcf.gz can be found in.

I guess what I am trying to do is search for each vcf.gzin

Code:
/home/cmccabe/nfs/exportedReports/Folder1/plugin_out/variantCaller*/{001,002,003}

Bash
Code:
a=/home/cmccabe/nfs/exportedReports;DEST="/home/cmccabe/Desktop/NGS/API/$DATE";
while read line; do find $a/$line -name "*vcf.gz" -exec cp {} $DEST \;
done < out.txt

contents of out.txt
Code:
Folder1

within Folder1
Code:
plugin_out

next level Folder1/plugin_out
Code:
variantCaller_out.40

next level Folder1/plugin_out/variantCaller_out.40
Code:
001
002
003

Currently I am getting syntax errors. Thank you Smilie.

Last edited by cmccabe; 09-19-2016 at 04:40 PM.. Reason: added details
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

string search in folders with particular multiple file extension

Hi, I am newbie in UNIX so please excuse for my questions. Is there a a way to search for string in files within folder and sub folder in particluar file extensions. Ex. search for ABC in folder 'A'(including it's sub folders) in html, xml files. Thanks, Ani (2 Replies)
Discussion started by: anikanch
2 Replies

2. Shell Programming and Scripting

Search for multiple strings in specific position

Hi, I need to search for some strings in specific positions in a file. If the strings: "foo1", "foo2" or "foo3" is on position 266 or position 288 in a file i want the whole line printed. Any idea how to do it? (5 Replies)
Discussion started by: HugoH
5 Replies

3. Shell Programming and Scripting

Find files of specific size excluding search in a subdirectory

Hi All, I was exploring find command and came across -prune option which would exclude search in a mention subdirectory. My quesry is to search all files more that 100 MB size but exclude search in a subdirectory. I am using below command,but somehow it is not working. Can anybody help me... (6 Replies)
Discussion started by: usha rao
6 Replies

4. Shell Programming and Scripting

Find files of type within folder copy multiple results to different folders

Ok question number two: I'd like to search a directory for multiple file types (rar, txt, deb) and depending on what's found, copy those files to folders named Rar, TextFiles, and Debs. I'm looking for speed here so the faster the script the better. I want it to be a function that I pass 1 argument... (4 Replies)
Discussion started by: DC Slick
4 Replies

5. Shell Programming and Scripting

Search for file and size subdirectory as well

Hi I made this code to search in directory for file and size How can I remodel it to seach in the sub direcotry as well Thanks #!/bin/bash echo -n "Enter: " read var if then echo "Directory exists: ${var}" size=`du -hs "${var}"` echo The size of the current folder is... (4 Replies)
Discussion started by: lio123
4 Replies

6. Shell Programming and Scripting

Script to search specific folders dates /mm/dd/ structure

Hi, I have a script that handles a huge amount of log files from many machines and copies it into a SAN location with the following directory structure: /SAN/machinenames/yyyy/m/d so for example /SAN/hosta/2011/3/12/files* Now I am writing a bash script to search for files between to date... (4 Replies)
Discussion started by: GermanJulian
4 Replies

7. Shell Programming and Scripting

how to count how many subdirectory containing more than a certain number of specific file type

hi I want to write a script which count the number of subdirectories in the current root directory that contain more than a specified number of files of a specific type. Is there an easy way to do this? Thanks Robert (2 Replies)
Discussion started by: piynik
2 Replies

8. Shell Programming and Scripting

Gunzip,grep and zip across folders in a subdirectory

I have a simple function that greps within a folder into files that are already gunzipped. This was already written for me so from my understanding fn=$1 specifies that it will look into any file in that folder that is gunzipped and the rest of the script greps the data its looking for and puts it... (3 Replies)
Discussion started by: red56
3 Replies

9. Shell Programming and Scripting

Copying specific file types to specific folders

I am trying to write a script that cycles through a folder containing many folders and when inside each one it's supposed to copy all the .fna.gz files to a folder elsewhere if the file and the respective folder have the same name. for fldr in /home/playground/genomes/* ; do find .... (8 Replies)
Discussion started by: Mr_Keystrokes
8 Replies

10. UNIX for Beginners Questions & Answers

How to use a grep search to search for a specific string within multiple directories?

Lets say I have a massive directory which is filled with other directories all filled with different c++ scripts and I want a listing of all the scripts that contain the string: "this string". Is there a way to use a grep search for that? I tried: grep -lr "this string" * but I do not... (3 Replies)
Discussion started by: Circuits
3 Replies
All times are GMT -4. The time now is 06:03 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy