find and create hard link with regex in different path

125 views Asked by At

The below script finds a file, then creates a hard link in a destination path.

find /path/to/files -name "example" -exec ln {} /path/to/destination/ \;

I would like to create the link using the following

'y/./ /; s/[()]//g; s/^([^0-9]+)([0-9]+).*\s([a-z0-9]+)$/\1(\2).\3/;'

I've been trying to do this for a couple hours now. But with no success.

2

There are 2 answers

0
David Custer On

I figured it out!

new_movie_name=$(find "$TR_TORRENT_DIR/$TR_TORRENT_NAME" -type f -size +500M \! -iname "*sample*" \! -iname "*s[0-9][0-9]*" \! -iname "*e[0-9][0-9]*" \! -iname "*s[0-9][0-9]e[0-9][0-9]*" \! -iname "*s[0-9]e[0-9][0-9][0-9]*" \! -iname "*[0-9]x[0-9][0-9]*" \( -iname "*19[0-9][0-9]*" -o -iname "*20[0-9][0-9]*" \) -exec basename {} \;)

new_movie_directory=$(find "$TR_TORRENT_DIR/$TR_TORRENT_NAME" -type f -size +500M \! -iname "*sample*" \! -iname "*s[0-9][0-9]*" \! -iname "*e[0-9][0-9]*" \! -iname "*s[0-9][0-9]e[0-9][0-9]*" \! -iname "*s[0-9]e[0-9][0-9][0-9]*" \! -iname "*[0-9]x[0-9][0-9]*" \( -iname "*19[0-9][0-9]*" -o -iname "*20[0-9][0-9]*" \) -exec dirname {} \;)

plex_movie_directory="/hdd_bottom-left/plex/movie"

ln "$new_movie_directory/$new_movie_name" "$(echo "$plex_movie_directory/$new_movie_name" | sed -r 'y/./ /; s/[()]//g; s/^([^0-9]+)([0-9]+).*\s([a-z0-9]+)$/\1(\2).\3/;')"
2
smathy On

Might be simpler to just throw those lines in a perl file and run that in your find. You'll struggle running this on the command line in the -exec with the many layers of escaping you'll need.