Search code examples
terminalcommand-linegoprogpr-tools

What is the best way to recursively run a Terminal command with a changing variable in the command?


I have a few thousand GoPro RAW images, and the best way to convert them to a workable format is to use their command line conversion tool in the following format:

$ gpr_tools -i /path/G0028513.GPR -o /path/G0028513.DNG

The filenames are sequential, so is there is a way to create a loop where I have a start and end variable that represents the first and last files (eg. 28513, and 33512), and add one to that number on each iteration to use in the two "path" sections of the command?


Solution

  • for i in {16243..28784}
    
    do
    
      /gpr/build/source/app/gpr_tools/gpr_tools -i /path-to-GPR-files/G00$i.GPR -o /path-to-DNG-folder/G00$i.DNG
    
    done
    
    • Change the path to gpr_tools to where you have yours located. Eg. "/gpr/build/source/app/gpr_tools/gpr_tools"
    • Change the input path to where your RAW .GPR files are. I'm reading and writing to my SD card, so my path is actually "/Volumes/256GB/DCIM/GPR/"
    • Change the output path to where you want them saved.
    • Change the two numbers at the top to represent the first file, and the last file. My first file is G0016239.GPR, last file is G0028784.DNG. I actually changed my camera settings mid-way through this timelapse, going from day to night, so my files jump from 18xxx to 28xxx. But the script will just skip all the missing numbers in between, and continue correctly when it hits correct files.

    Happy shooting!