capturing renamed result as variable
Posted: 15 Dec 2016, 05:03
Hey there, looking from some new ideas on this as I've been racking my brain for a couple days. I have a script that parses files and renames/moves them to the appropriate folders. I've set this as a command substitution so I can refer to the output of filebot and pull more data from it, being the renamed files.
the results are spotty especially with special characters in the names such as ' . and it seems to be a word splitting issue with running it in a command subsitution. if I check the logs that it creates it shows fine, but the live output and whats being stored in the variable is wrong so when I go to massage the output it's random.
example.. live output which is stored in variable - notice the '\''
Whats shown in the log file and what it's actually being called
so any ideas on how to tackle this? I've tired different method of quotes, trying to sed the output, just trying to suppress the word splitting. the key is whatever solution it has to work with files that dont have special characters and ones that do. I've thought about creating a log for each rename and parsing that, just think that will lead to a file management issue..
Code: Select all
moviefilebot=$(filebot.sh -rename --conflict $filebotconflictmode -no-xattr --log-file $filebotlog --format '{n.replace('\'':'\'','\'' -'\'')} ({y}){'\'' CD'\''+pi}{'\''.'\''+lang} {tags.join('\'', '\'')}' --action $filebotmode $remotemoviefolder/$Releasename --db $filemoviedb --output "/mnt/Movies/" -non-strict &)
Code: Select all
renamedmkv=$(echo $moviefilebot | awk -F"/mnt/Movies/" '{print $2}' | sed "s/].*//g" | sed "s/'/\'\'/")
renamedidx=$(echo $moviefilebot | awk -F"/mnt/Movies/" '{print $3}' | sed "s/].*//g" | sed "s/'/\'\'/")
renamedsub=$(echo $moviefilebot | awk -F"/mnt/Movies/" '{print $4}' | sed "s/].*//g" | sed "s/'/\'\'/")
example.. live output which is stored in variable - notice the '\''
Code: Select all
[TEST] Rename [/home/user/files/movie/Miss.Peregrines.Home.for.Peculiar.Children.2016.1080p.BluRay.x264-SPARKS/Miss.Peregrines.Home.for.Peculiar.Children.2016.1080p.BluRay.x264-SPARKS.mkv] to [/mnt/movies/Miss Peregrine'\''s Home for Peculiar Children (2016).mkv]
Processed 1 files
Code: Select all
[TEST] Rename [/home/user/files/movie/Miss.Peregrines.Home.for.Peculiar.Children.2016.1080p.BluRay.x264-SPARKS/Miss.Peregrines.Home.for.Peculiar.Children.2016.1080p.BluRay.x264-SPARKS.mkv] to [/mnt/movies/Miss Peregrine's Home for Peculiar Children (2016).mkv]
Processed 1 files