I need to create filelist (playlist) for using it in a Docker container. So the path of the file on the host system is not the mounting path. Now I try to fix this, but I have some trouble.
This is my script where I want to add the replacement
tdir="/mountingpoint"
readarray -d $'\0' listing < <(find "${fdir}"/*.mp3 -print0)
#for mixing up and write to file
listing=( $(shuf -e "${listing[@]}") )
printf "%s\n" "${listing[@]}" > "playlist.m3u"
A common way should be the use of sed
but I have some trouble by putting things together.
I think I have to modify the script to something like readarray -d $'\0' listing < <(find "${fdir}"/"${d}"/ -name "*.mp3" -print0 -exec sed -i "s/"$fdir"/"$tdir"/" {} \;)
but this result in an error sed: -e expression #1, char 9: unknown option to `s'
I think the slash in the dir name cause this error. But I also tried to replace the variables with a folder name to check the result, but nothing happened (beside a longer runtime). Nothing means no replacement in the output file.
I hope someone can handle my bad English and give me a hint what I do wrong. Thanks a lot
/
as the sed pattern delimiter but also have/
in the pattern and replacement strings - see for example How to replace a string with a string containing slash with sed?. But there are other issues. – steeldriver Aug 15 '22 at 21:49-exec
option tofind
, this is invoking sed on the files, not the file names. I think you want `find "${fdir}/${d}" -name *.mp3 -print | sed "s=$fdir=$tdir=". I have dropped the -print0 which is good practice but currently confusing. Let us know how you get on and I can write up an answer if no one beats me to it. – icarus Aug 16 '22 at 03:05