非常に具体的な名前の複数のテスト ディレクトリがあり、それらのディレクトリ内に、複数のサブ ディレクトリを持つ複数のサブ ディレクトリがあります。
例:
*./V01A1A01/S01/R00/JADE/Anytest.drec
*./V01A1A01/S01/R01/JADE/Anytest.drec (サブディレクトリ R01 が異なることに注意)
等...
*./V01A1A01/S02/R00/JADE/Anytest.drec
*./V01A1A01/S02/R01/JADE/Anytest.drec (S02 とサブディレクトリ R01 が異なることに注意)
等...
Anytest.drec
すべてのディレクトリを、時々変更するソース ファイル "Anytext.drec" (path=/home/mike/Desktop/Active_Test/Source_Files/Anytest.drec)に置き換えて名前を変更したいと考えています。Anytest.drec が V01_A1_A01_S01_R00.drec.
これまでの私のコードは次のとおりです。
#!/bin/bash
path1=/home/mike/Desktop/Active_Test/Source_Files/Anytest.drec #set path of source Anytest.drec file
set -x #allows me to see what things are going on with code
echo "Please enter the Master folder you wish to search or update" #asks user for the input folder to search
read "folder" #creates variable "$folder" and sets the directory I want to search
jade_files=`find /home/mike/Desktop/Active_Test/$folder -name "*.drec" -print`
#finds all filenames in var $folder with the extension of .drec and puts the result in var $jade_files which now = /home/mike/Desktop/Active_Test/V01A1A02/S00/R00/JADE/Anytest.drec
path=`dirname "$jade_files"` #dirname gives full paths of .drec files and puts result into var $path
ext=${jade_files##*.} #uses the var $jade_file to get the extension of .drec files found in the find search which = drec
basename=`basename "$jade_files"` #gets the basenames from var $file which = Anytest.drec
#here's where my problems start... I'm trying to use the content of var "$jade_folders" to cp /Source_Files/Anytest.drec into var "$jade_folders" path(s) and using awk to parse out the portion of the dirname want to reconfigure into the filename
while read -r line; do
new_name=| `awk '{print $5, "_", $6, "_", $7 }'`
echo $new_name
cp -b /home/mike/Desktop/Active_Test/Source_Files/"$new_name"."$ext" "$line"
done <<< "$jade_folders" #essentially, this var is the input to the while loop and <<< is how it's done.
私が得たものはこれです:
cp: cannot stat ‘/home/mike/Desktop/Active_Test/Source_Files/.drec’: No such file or directory
このスクリプトを修正して、希望どおりに動作させるにはどうすればよいですか?
わかりました、これは私が最終的に使用した修正です。すべてのアンダースコアを配置するわけではありませんが、ほとんどを配置します。残りの部分は、さらに学習しながら修正します。ありがとうエド:
#!/bin/bash
path1=/home/mike/Desktop/Active_Test/Source_Files/Anytest.drec
set -x
echo "Please enter the Master folder you wish to search or update"
read "folder"
jade_files=`find /home/mike/Desktop/Active_Test/$folder -name "*.drec" -print`
path=`dirname "$jade_files"`
ext=${jade_files##*.}
basename=`basename "$jade_files"`
cp -b "$path1" "$jade_files"."$ext"