나는 매우 특정한 이름을 가진 다중 테스트 디렉토리를 가지고 있으며, 그 디렉토리 내에 여러 하위 디렉토리가있는 여러 하위 디렉토리가 있습니다.여러 디렉토리에있는 여러 파일의 파일 이름에 dirname을 어떻게 전달합니까?
예 :..
*/V01A1A01/S01/R00/JADE/Anytest.drec는
*/V01A1A01/S01/R01/JADE/Anytest.drec
등 ...
. */V01A1A01은/S02은 /은 R00/JADE/Anytest.drec
. */V01A1A01/S02/R01/JADE/Anytest.drec (참고 S02 서브 디렉토리 R01은 이제 상이)
등 ...
모든 디렉토리에있는 Anytest.drec
을 내가 바꿀 때마다 변경하는 소스 파일 "Anytext.drec"(경로 =/home/mike/Desktop/Active_Test/Source_Files/Anytest.drec)로 바꾸고 싶습니다./JADE 디렉토리의 최종 이름에서 dirname을 가져 와서 Anytest.drec이 이제 V01_A1_A01_S01_R00.drec을 읽도록합니다.
여기 내 코드는 지금까지의 :
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 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.
내가 나갈 것은이 무엇입니까?
괜찮 았어, 이건 내가 사용 끝난 수정이다, 그것은 밑줄을 모두 넣지는 않지만 대부분 넣는다. 나는 더 많은 것을 배울 때 나머지 부분을 고칠 것이다. 감사 에드 :
나는 당신이 그렇게 먼저 정리에게의 스크립트의 구문을하게하고 당신이 원하는 것을하고 그렇지 않으면 당신이 우리를 말할 수 있는지 확인해야 할 노력하고 무엇을 알아낼 수 없습니다#!/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"
'new_name = | 행의 의도는 무엇입니까? \ awk \ print $ 5, "_", $ 6, "_", $ 7} '\''? 'path1'은 어떻게 사용 되나요? 왜'folder'와'directory'라는 단어를 사용하고 있습니까? 동일한 것을 의미하겠습니까 (UNIX는 폴더가 없습니다)? –
'find .. -exec "명령"'을 사용하여하려는 것을 달성 할 수있을 것 같습니다. 일반적인 요점으로, 당신은 후행 구문 **'** '이 아닌'$ (command)'를 사용해야합니다. 왜냐하면 후자의 구문이 더 이상 사용되지 않기 때문입니다. –
내 생각에 awk는 내가 사용한 dirname의 섹션을 구문 분석하여 var $ new_name에 넣은 다음 var $ new_name을 사용하여 Anytest.drec의 이름을 밑줄을 사용하여 바꿉니다. 그것은 작동하지 않았고 그것을 고칠 방법을 모른다. 폴더와 디렉토리에 관해서는, 나는 리눅스에 익숙하지 않고 내가가는 동안 그것을 배우려고 노력하고있다. 단어의 오용을 유감스럽게 생각합니다. –