我有一個特定的集合(全部以.bam
結尾)下載的文件在目錄/home/cmccabe/Desktop/NGS/API/2-15-2016
中。我正在嘗試使用匹配 name
來重命名下載的文件。爲了讓事情更加複雜,文件夾的日期是唯一的,並且在name
的標題中存在比賽日期,並且是name
中的比賽所在的位置。我不知道如何做到這一點,或者如果可能的話。謝謝 :)。文件夾的將目錄中的特定文件擴展名重新命名爲與bash中的另一個文件匹配
內容/home/cmccabe/Desktop/NGS/API/2-15-2016
IonXpress_001.bam
IonXpress_002.bam
IonXpress_003.bam
IonXpress_007.bam
file1.gz
file2.gz
名稱
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
期望結果
testname1_12345.bam
testname2_45678.bam
testname3_9012.bam
testname1_12345.bam
file1.gz
file2.gz
慶典到目前爲止
logfile=/home/cmccabe/Desktop/NGS/API/2-15-2016/process.log
for f in /home/cmccabe/Desktop/NGS/API/2-15-2016/*.bam ; do
echo "patient identifier creation: $(date) - File: $f"
bname=$(basename $f)
pref=${bname%%.bam}
while read from to ; do
for i in $f* ; do
if [ "$i" != "${i/$from/$to}" ] ; then
mv $i ${i/$from/$to}
fi
done < names.txt
echo "End patient identifier creation: $(date) - File: $f"
done >> "$logfile"
編輯:
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/names.txt)
echo "$cmd"
done
sed: -e expression #1, char 4: extra characters after command
在該文件夾的結束日期('/家庭/ cmccabe /桌面/ NGS/API/2-15-2016')將匹配'name'中的頭部,並且這是匹配所在的位置。非常感謝你 :)。 – Chris
對於那些錯別字,我很抱歉,文件中應該有一個總是匹配的地方。如果沒有匹配,那麼它應該是錯誤的。謝謝 :)。 – Chris