[英]How to move files based on file (file name and location in file)
I tried but I failed, I have file like: 我试过了但是失败了,我有这样的文件:
06faefb38081b44e35b4ee846bfb84b61694a5c4.zip D:/code/3635/
0a386c77a3ae35033006efec07bfc37f5236212c.zip D:/code/3622/
0b425b29c3e51f29b9af03db46df0aa8f726705b.zip D:/code/3624/
0ecb477c82ec540c8eb0642da144a400bbf3f7c0.zip D:/code/3624/
...
My goal is to move file in first column to location in second column. 我的目标是将第一列中的文件移动到第二列中的位置。 I tried with while+awk but this did not worked.
我尝试了while + awk,但是没有用。 I would appreciate any help!
我将不胜感激任何帮助!
awk '{ system("mv "$1" "$2) }' filename
With awk, you can use the system function to build a move command and excute it. 使用awk,您可以使用系统功能来构建移动命令并将其执行。 Obviously ensure that you are running the command in the directory with the files.
显然,请确保您正在包含文件的目录中运行命令。
假设您的文件名为“ data.txt”,因此您的代码可能如下所示:
while read line; do mv $line; done < data.txt
What you need is just add a mv (space)
to the beginning of each line. 您只需要在每行的开头添加一个
mv (space)
即可。 So you have 100+ ways to do that. 因此,您有100多种方法可以做到这一点。 If you love awk:
如果您喜欢awk:
awk '$1="mv "$1' file
will create the mv
command, to execute them, you can: 将创建
mv
命令,以执行它们,您可以:
awk '$1="mv "$1' file |sh
I prefer this than the system()
function call. 我比
system()
函数调用更喜欢它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.