Path 如何复制目录中的多个文件并将每个文件移动到正确的目录中

Path 如何复制目录中的多个文件并将每个文件移动到正确的目录中,path,directory,find,copy,cat,Path,Directory,Find,Copy,Cat,unixshellksh 我创建了一个文件列表,目前正在尝试将每个文件复制到正确的路径 (mylist) -1111 -2222 -3333 -4444 -5555 当前目录 /样本/目录/未知/ -1111fileneeded.txt -2222fileneeded.txt -3333fileneeded.txt -4444fileneeded.txt -5555fileneeded.txt -6666dontneed.txt -7777dontneed.txt -8888dontneed.

unixshellksh

我创建了一个文件列表,目前正在尝试将每个文件复制到正确的路径

(mylist)
-1111
-2222
-3333
-4444
-5555
当前目录 /样本/目录/未知/

-1111fileneeded.txt
-2222fileneeded.txt
-3333fileneeded.txt
-4444fileneeded.txt
-5555fileneeded.txt
-6666dontneed.txt
-7777dontneed.txt
-8888dontneed.txt
...etc
每个文件的前4个字符与其所需位置的正确路径相匹配

/sample/dir/1111/
/sample/dir/2222/
/sample/dir/3333/
/sample/dir/4444/
这就是我目前拥有的

for i in `cat mylist`
do echo "$i"
 find /sample/dir/unknown/mylist* 
这就是我被卡住的地方,我试图弄清楚需要做什么才能将每个文件移动到正确的目录中

这应该行得通

#!/bin/ksh
while IFS=\| read -r line; do
   dir=`echo $line | cut -c 2-5`
   mv "$line /sample/$dir/$line"
done > filelist.txt
IFS
是转义特殊字符,以防万一

cut-c2-5
将所有字符从2提取到5(因为文件名的开头有一个破折号)

如果您还有什么不明白的地方,请告诉我。

这应该可以

#!/bin/ksh
while IFS=\| read -r line; do
   dir=`echo $line | cut -c 2-5`
   mv "$line /sample/$dir/$line"
done > filelist.txt
IFS
是转义特殊字符,以防万一

cut-c2-5
将所有字符从2提取到5(因为文件名的开头有一个破折号)


如果您还有其他不明白的地方,请告诉我。

您使用的是什么平台和shell?抱歉,是的,我使用的是shell/哪个/shell?bash,csh,tcsh,sh,…?unix shell ksh。您使用的是什么平台和shell?抱歉,是的,我使用的是shell/Which/shell?bash,csh,tcsh,sh,…?unixshellksh。非常感谢!如果我的回答有帮助,你能投票/接受吗?嗨,威尔,我接受了,但我不能投票,因为我还没有足够的代表来投票。但是非常感谢!非常感谢你!如果我的回答有帮助,你能投票/接受吗?嗨,威尔,我接受了,但我不能投票,因为我还没有足够的代表来投票。但是非常感谢!