Reputation: 465
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 -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?
Upvotes: 0
Views: 386
Reputation: 785266
You can use -execdir
option of find
for this renaming and avoid xargs
altogether:
find "$SOURCEFOLDER" -type f -execdir bash -c 'sed "s/\[[^][]*\]//g" <<< "$1";
ln "$1" "$ENDFOLDER/$TR_NEW_TORRENT_NAME/${basename}"' - '{}' \;
Upvotes: 1
Reputation: 2160
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
find "$SOURCEFOLDER" -type f -exec sed -e 's/\[[^][]*\]//g' {}\; -exec ln {} "$ENDFOLDER/$TR_NEW_TORRENT_NAME/${basename}" \;
I hope this will help.
Upvotes: 1