bashcommand-linemkv

Join splitted -001.mkv files with bash


I have some -001.mkv files splitted in this way

the rings + of power-001.mkv
the rings + of power-002.mkv
..

nightmare.return-001.mkv
nightmare.return-002.mkv
..

I need to join -001.mkv files to obtain files like this

the rings + of power.mkv
nightmare.return.mkv

I thought of such a code, but doesn't work

for file in "./source/*001.mkv;" \
do \
    echo mkvmerge --join \
    --clusters-in-meta-seek -o "./joined/$(basename "$file")" "$file"; \
done

source is the source folder where -001.mkv files are located
joined is the target folder


Solution

  • Can you try this?

    for f in ./source/*-001.mkv
    do
        p=${f%-001.mkv}
        echo mkvmerge --clusters-in-meta-seek \
            -o ./joined/"${p##*/}".mkv "$p"-*.mkv
    done
    

    Given your example, the for f in ./source/*-001.mkv should loop though nightmare.return-001.mkv and the rings + of power-001.mkv.
    Let's assume that we're in the first iteration and $f expands to nightmare.return-001.mkv

    So ... -o ./joined/"${p##*/}".mkv "$p"-*.mkv would be equivalent to ... -o ./joined/nightmare.return.mkv ./source/nightmare.return-*.mkv

    PS: Once you checked that the displayed commands correspond to what you expect then you can remove the echo