0

So I am trying to write a script in bash which will add the relative path to the beginning of each line of the concat_files.txt and then I want to concatenate all files and put the output file in the same directory defined in the path variable. So far, the sed command is working fine, I just need to find out how I can insert the path in front of the output file. The easiest way is by concatenating them in the current directory and then moving the output file to the path variable, but I don't have enough place in my current directory, so this is not an option.

#!/bin/bash

# Script that concatenates all the files defined in concat_files.txt

path=/mnt/disk/video_evaluation/XDROOT/Clip/

sed -i "s@^@file '$path@" concat_files.txt
sed -i "s/$/'/" concat_files.txt


ffmpeg -f concat -i concat_files.txt -c copy $path/output.mxf

And maybe another improvement to the script would be if I can select all files with some specific extension and put them in the file. But I am not sure how I can do that either...

  • 1
    What, in particular, fails with your current solution? Also, you may not want to do an in-place edit with sed here, both because the -i flag is non-portable and because it will prevent running your script twice on the same input. – Fox Feb 15 '17 at 11:17
  • @Fox I just want the output file to be placed in the "path" directory. It works fine the script, and yes, I could use sed -e and save the changes in a new file, because otherwise every time I am running the script the sed command will append these characters. Right now when I run the script it saves the output file in the same category where the script is and it also cannot select all files with the MXF extension and to put them to a file. – Georgе Stoyanov Feb 15 '17 at 14:36
0

actually @fox was right, the script works just fine, I have modified it slightly to accommodate the changes suggested by him:

#!/bin/bash

# Script that concatenates all the files defined in concat_files.txt
path=/mnt/disk/video_evaluation/XDROOT/Clip/

sed -e "s@^@file '$path@" concat_files.txt > new.txt
sed -e "s/$/.MXF'/" new.txt > final.txt
ffmpeg -f concat -safe 0 -i final.txt -c copy $path/output.mxf

Now I only miss the functionality to add the files with a specific extension to a file.

  • Adding files with a specific extension can be done with find. Try find $path -name '*.extension' -printf "file '$path/%p'\n" and see if that gives you what you want – Fox Feb 15 '17 at 16:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.