How do I merge files with partial filename matches
Posted: 2017-04-21T08:03:18-07:00
This is probably easy but I'm having trouble finding the proper commands and scripting isn't my expertise. I've gone through the examples and searched the documentation multiple times over the past couple days. Any assistance is greatly appreciated.
I'm trying to convert and merge image files based on a partial match of the file name. I've been able to script entire directories and target specific filetypes for conversion/mogrify and merging, but now I'm looking to target those based on matching characters of a filename. My example below might better explain it.
Source file list - format is "type_name_pagenumber.filetype":
fruit_orange_1.tif (single page)
fruit_orange_2.tif (single page)
fruit_orange_3.tif (single page)
fruit_banana_1.tif (single page)
fruit_banana_2.tif (single page)
fruit_apples_1.pdf
fruit_tomato_1.pdf
End result I'm aiming for:
fruit_orange.tif (combined multipage - 3 pages)
fruit_banana.tif (combined multipage - 2 pages)
fruit_apples_1.pdf (untouched)
fruit_tomato_1.pdf (untouched)
In the above example, the TIF files have a type prefix (fruit) that will remain the same forever but the following name (orange) and page number (#) will change daily. I'd like to merge all files that have a matching "type_name_" in the filename of the .TIF filetype. The filenames are a fixed length, down to the type, name, page number and filetype.
After the files that belong together are together, I'd convert them to PDF, which I'm already familiar with.
Is the above possible?
I'm trying to convert and merge image files based on a partial match of the file name. I've been able to script entire directories and target specific filetypes for conversion/mogrify and merging, but now I'm looking to target those based on matching characters of a filename. My example below might better explain it.
Source file list - format is "type_name_pagenumber.filetype":
fruit_orange_1.tif (single page)
fruit_orange_2.tif (single page)
fruit_orange_3.tif (single page)
fruit_banana_1.tif (single page)
fruit_banana_2.tif (single page)
fruit_apples_1.pdf
fruit_tomato_1.pdf
End result I'm aiming for:
fruit_orange.tif (combined multipage - 3 pages)
fruit_banana.tif (combined multipage - 2 pages)
fruit_apples_1.pdf (untouched)
fruit_tomato_1.pdf (untouched)
In the above example, the TIF files have a type prefix (fruit) that will remain the same forever but the following name (orange) and page number (#) will change daily. I'd like to merge all files that have a matching "type_name_" in the filename of the .TIF filetype. The filenames are a fixed length, down to the type, name, page number and filetype.
After the files that belong together are together, I'd convert them to PDF, which I'm already familiar with.
Is the above possible?