The bash below loops through a specific directory dir and finds and writes the oldest folder to a variable called $filename.
Result output stored in /home/cmccabe/medex.logs/folder.log
The variable (in bold) is also written to a log file stored at/home/cmccabe/medex.logs/folder.log.
So the R_2017_01_13_12_11_56_user_S5-00580-24-Medexome would be extracted and saved as $filename for the below processes to use.
So basically store the portion in bold from the log in the filename variable so the other lines can use it to execute.
The problem is there could be multiple lines in the log, but only one returned from the bash. The line that is returned from the bash
needs to be matched to a line in log and stored as filename.
So in the log there may be 3 lines:
But on 1 returned by the bash
So, R_2017_01_13_12_11_56_user_S5-00580-25-Medexome would be stored in the $filename variable.
I am really not sure how to do this and hope I posted enough information. Thank you :).
Code:
#!/bin/bash
# oldest folder stored as variable for analysis, version log created, and quality indicators matched to run
dir=/home/cmccabe/Desktop/NGS/test
find "$dir" -maxdepth 1 -mindepth 1 -type d -printf '%T+\t%P\0' | sort -rz |
while read -r -d $'\t' time && read -r -d '' filename
do
printf "The oldest folder is $filename, created on $time and analysis done using v1.4 by $USER at $(date "+%D %r")\n" >> /home/cmccabe/medex.logs/folder.log
awk -v FL="$filename" '
FNR == 1 {filenum++}
filenum==1 && index($0, FL) {
match($0, "_0*([0-9]+)/")
FNUM=substr($0,RSTART+1,RLENGTH-2)
gsub(/^0+/,"", FNUM)
}
filenum==2 && $0 ~ FNUM".pdf$"' /home/cmccabe/s5_files/downloads/list /home/cmccabe/s5_files/pdf/pdf > /home/cmccabe/s5_files/pdf/output
break
done
Code:
The oldest folder is R_2017_01_13_12_11_56_user_S5-00580-24-Medexome, created on 2017-01-17+11:31:02.5035483130 and analysis done using v1.4 by cmccabe at 01/17/17 12:41:03 PM
So the R_2017_01_13_12_11_56_user_S5-00580-24-Medexome would be extracted and saved as $filename for the below processes to use.
Code:
(these are just two of 50 that all use the $filename variable)
mkdir -p /home/cmccabe/Desktop/NGS/API/$filename/{bam/{validation,coverage},bedtools,fastqc,hgmd,igv,panel/{reads,},panel/20x/{base,gene,percent},panel/{reads,},panel/30x/{base,gene,percent},pdf,picard,torrent,vcf/overall/{annovar,stats},vcf/panel/{annovar,}}
# create analysis log
echo "analysis done using v1.4 by $USER at $(date "+%D %r")" > /home/cmccabe/Desktop/NGS/API/$filename/analysis.txt
The problem is there could be multiple lines in the log, but only one returned from the bash. The line that is returned from the bash
needs to be matched to a line in log and stored as filename.
So in the log there may be 3 lines:
Code:
R_2017_01_13_12_11_56_user_S5-00580-24-Medexome, created on 2017-01-17+11:31:02.5035483130 and analysis done using v1.4 by cmccabe at 01/17/17 12:41:03 PM
R_2017_01_13_12_11_56_user_S5-00580-25-Medexome, created on 2017-01-17+11:31:02.5035483130 and analysis done using v1.4 by cmccabe at 01/17/17 1:22:09 PM
R_2017_01_13_12_11_56_user_S5-00580-26-Medexome, created on 2017-01-17+11:31:02.5035483130 and analysis done using v1.4 by cmccabe at 01/17/17 2:11:44 PM
Code:
R_2017_01_13_12_11_56_user_S5-00580-25-Medexome
I am really not sure how to do this and hope I posted enough information. Thank you :).