1

I'm testing out bash filename replacement with parameter expansion as shown here: How to change file extension in Linux shell script?

However, I can't seem to get the following to work as I intend:

given the following files:

tmp/01. Losing A Whole Year.flac
tmp/02. Narcolepsy.flac

I run find for flac files into parallel running the echo command for testing output. I'm trying to replace .flac with .mp3.

find tmp -type f -name '*.flac' | time parallel -j+0 --eta 'echo "{} {.flac%%.mp3}"'

My output is:

tmp/01. Losing A Whole Year.flac {.flac%%.mp3}
tmp/02. Narcolepsy.flac {.flac%%.mp3}

I'm planning on using this with ffmpeg if that makes a difference.

Edit: Expected output:

tmp/01. Losing A Whole Year.flac tmp/01. Losing A Whole Year.mp3
tmp/02. Narcolepsy.flac tmp/02. Narcolepsy.mp3

Edit 2: To replace the file extension, I can use:

find tmp -type f -name '*.flac' | time parallel -j+0 --eta 'echo "{} {.flac%%.mp3}"'

However, this provides the following output

tmp/01. Losing A Whole Year.flac tmp/01.\ Losing\ A\ Whole\ Year.mp3
tmp/02. Narcolepsy.flac tmp/02.\ Narcolepsy.mp3

Maybe this is an ffmpeg question now, because ffmpeg will not be able to find the file if there's a \ character in place of a space character.

1
  • Things are not working as expected because you are using Parallel substitutions, not Bash. Bash substitutions are prefixed with $. Commented Nov 15, 2015 at 17:37

1 Answer 1

1

I think I figured it out:

find tmp -type f -name '*.flac' | time parallel -j+0 --eta 'echo "{} {.}.mp3"'

will produce the expected results.

Although, I don't know why this doesn't work:

find tmp -type f -name '*.flac' | time parallel -j+0 --eta 'echo "{} {.flac}.mp3"'

Edit: While the above seems to work, \ characters are inserted to replace blank spaces, which would cause ffmpeg to not find the desired files.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.