我正在尝试通过find复制由REGEX表达式选择的图像。下面的命令会运行,但不会复制文件。如何将循环变量(例如读取文件行)传递给find -regex参数?
cat hit_images_regex_list.txt | while read line;
do
find . -regex "${line}" -exec cp --parents {} /destination_dir \;
done我从中提取REGEX表达式的hit_images_regex_list.txt文件如下所示:
".*B - 12.*tif"
".*D - 09.*tif"
".*G - 03.*tif"
".*G - 12.*tif"
...将find与这些REGEX表达式一起使用是可行的,但是从我的.txt文件中提取REGEX表达式的循环不会做任何事情。
发布于 2020-02-13 08:36:56
for i in $(cat hit_images_regex_list.txt); do find -name "$i" | cat -n | while read n f; do cp "$f" /newfolder/path/"$n".tig; done; done这将打开该文件,并为每个正则表达式(行)查找所有匹配的文件并将其复制到新文件夹
这有帮助吗?
发布于 2020-02-13 08:42:44
尝尝这个。
while IFS= read -r line; do
find . -regex "$line" -exec cp --parents {} /destination_dir \;
done < hit_images_regex_list.txt发布于 2020-03-31 16:39:56
人们已经花了时间去尝试和帮助。请对我们的回复进行礼貌评分
https://stackoverflow.com/questions/60195982
复制相似问题