I have a specific set (all ending with .bam) of downloaded files in a directory /home/cmccabe/Desktop/NGS/API/2-15-2016. What I am trying to do is use a match to $2
in name
to rename the downloaded files. To make things a more involved the date of the folder is unique and in the header of name
the date of the match exists and is where the match in name
is located. I am not sure how to do this or if it is possible. I have tried a sed
command with no luck, maybe that isn't the best way. Thank you :).
contents of folder /home/cmccabe/Desktop/NGS/API/2-15-2016
IonXpress_001.bam
IonXpress_002.bam
IonXpress_003.bam
IonXpress_007.bam
file1.gz
file2.gz
name
2-15-2016
IonXpress_001.bam testname1_12345
IonXpress_002.bam testname2_45678
IonXpress_003.bam testname3_9012
IonXpress_007.bam testname1_12345-
2-19-2016
IonXpress_001.bam testname5_00000
IonXpress_002.bam testname6_11111
IonXpress_003.bam testname7_1213
IonXpress_007.bam testname8_78524
sed tried:
for f in /home/cmccabe/Desktop/NGS/API/2-12-2016/*.bam ; do
bname=$(basename $f)
cmd=$(sed -n "/$f/,/[0-9]{1,2}-[0-9]{1,2}-20[0-9]{2}/{s/\(.*\.bam\) \(.*\)/mv \1 \2/p}" /home/cmccabe/Desktop/NGS/panels/name.txt)
echo "$cmd"
done
sed: -e expression #1, char 4: extra characters after command