Skip to content
Advertisement

Concatenate directory and file name in GNU parallel

I have the following directory structure:

dir1/file.ogg
dir2/file.ogg
dir3/file.ogg
     file2.ogg

I would like to convert all .ogg files to .wav with GNU Parallel. Here’s where I got thus far:

find . -name '*.*' -type f -print0 | parallel -0 ffmpeg -i {} outputdir/{/.}.wav

The problem here is that although obviously directories have different names, the files inside have the same name. The aforementioned command will continuously overwrite the content of the directory. What I’d like instead is:

outputdir/dir1_file.ogg
outputdir/dir2_file.ogg
outputdir/dir3_file.ogg
outputdir/dir3_file2.ogg

Essentially, I’d like to extract the subdirectory name and concatenate it with file basename and put my own extension.

Any ideas?

Advertisement

Answer

Using perl transformation, this command should achieve the required effect :

find . -name '*.ogg' -type f -print0 | parallel -0 echo ffmpeg -i {} outputdir/{= '$_ =~ s[^./][]; $_ =~ s[/][_]g; $_ =~ s[ogg$][wav]g;' =}

Remove echo to run ffmpeg command

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement