简体   繁体   English

将sed集成到find xargs copy shell命令中

[英]integrate sed into find xargs copy shell command

I have a script that I use to copy all of the files in one folder and move them to a new folder... the line i use to do it looks like this 我有一个脚本,可以将所有文件复制到一个文件夹中,然后将其移动到新文件夹中……我用来执行此操作的行如下所示

find "$SOURCEFOLDER" -type f | xargs -I {} ln {} "$ENDFOLDER/$TR_NEW_TORRENT_NAME/${basename}"

and it works perfectly 而且效果很好

the thing is I'd like to also use sed to remove any brackets from the basename of the new file but i don't know how to incorporate the sed command 事情是我也想使用sed从新文件的基本名称中删除任何括号,但是我不知道如何合并sed命令

sed -e 's/\[[^][]*\]//g' FILE

how would I go about doing this? 我将如何去做呢? Is there a better or simpler way to do all the things I want? 有没有更好或更简单的方法来完成我想要的所有事情?

I believe following will work for you: 我相信以下将为您工作:

find "$SOURCEFOLDER" -type f -exec bash -c "sed -e 's/\\[[^][]*\\]//g' {} ; xargs -I {} ln {} "$ENDFOLDER/$TR_NEW_TORRENT_NAME/${basename}" \\;

Idea is to combine the commands this ways: 想法是通过以下方式组合命令:

another way is to use two -exec 另一种方法是使用两个-exec

find "$SOURCEFOLDER" -type f -exec sed -e 's/\[[^][]*\]//g' {}\; -exec ln {} "$ENDFOLDER/$TR_NEW_TORRENT_NAME/${basename}" \;

I hope this will help. 我希望这将有所帮助。

You can use -execdir option of find for this renaming and avoid xargs altogether: 您可以使用-execdir的选项find这个重命名并避免xargs干脆:

find "$SOURCEFOLDER" -type f -execdir bash -c 'sed "s/\[[^][]*\]//g" <<< "$1";
    ln "$1" "$ENDFOLDER/$TR_NEW_TORRENT_NAME/${basename}"' - '{}' \;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM