bpatton_psr
asked on
Merge TIFF files with the same part of a filename
I have a directory with thousands of TIFF files. An example of the files are:
32202900_55967.tif
32202900_56130.tif
32206130_57427.tif
32206130_57515.tif
32209667_60298.tif
32209667_60508.tif
and so on...
As you can see, the first 8 digits of some of the filenames are exactly the same. These actually belong together as one file. I need a script that joins 2 (or more) TIFF files together which have the same first 8 digits AND removing the underscore and everything after it. So based on the above example, the final output should look like this:
32202900.tif
32206130.tif
32209667.tif
and so on...
Thanks in advance.
32202900_55967.tif
32202900_56130.tif
32206130_57427.tif
32206130_57515.tif
32209667_60298.tif
32209667_60508.tif
and so on...
As you can see, the first 8 digits of some of the filenames are exactly the same. These actually belong together as one file. I need a script that joins 2 (or more) TIFF files together which have the same first 8 digits AND removing the underscore and everything after it. So based on the above example, the final output should look like this:
32202900.tif
32206130.tif
32209667.tif
and so on...
Thanks in advance.
how these files were split
ASKER
Can't say. That's how we got them from a vendor. (!)
Give this a try. It makes several assumptions;
1) the numbers in places 10-14 in the file name determine how the join is made, lower numbers go first
2) all the file names are the same format
3) Simply cat'ing them together in the right order will preserve the tiff file integrity
last_file=""
for i in `ls *.tiff | sort -n`
do
first8=`echo $i | cut -c1-8`
filename=`echo $i | cut -c1-8,15-19`
if [ "$first8" != "$last_file" ]
then
echo "New File $filename"
last_file=$first8
cat $i > $filename
else
cat $i >> $filename
fi
done
1) the numbers in places 10-14 in the file name determine how the join is made, lower numbers go first
2) all the file names are the same format
3) Simply cat'ing them together in the right order will preserve the tiff file integrity
last_file=""
for i in `ls *.tiff | sort -n`
do
first8=`echo $i | cut -c1-8`
filename=`echo $i | cut -c1-8,15-19`
if [ "$first8" != "$last_file" ]
then
echo "New File $filename"
last_file=$first8
cat $i > $filename
else
cat $i >> $filename
fi
done
ASKER
Didn't work. Saved it as a .bat in the same directory. Ran it. Nothing happens.
oops this is bash shell for linux machine
ASKER
Ah, I am using a Windows machine.
ASKER
Hey. I wasn't sure if you were writing a script for a windows bat file or vbs. Thought I'd check.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Didn't get any response, so got help from different websites. Thought to post the solution here and close the question out.