?
Solved

Merge TIFF files with the same part of a filename

Posted on 2011-03-04
9
Medium Priority
?
1,282 Views
Last Modified: 2012-06-27
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.
0
Comment
Question by:bpatton_psr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 2
9 Comments
 
LVL 11

Expert Comment

by:Tasmant
ID: 35037927
how these files were split
0
 

Author Comment

by:bpatton_psr
ID: 35038063
Can't say. That's how we got them from a vendor. (!)
0
 
LVL 8

Expert Comment

by:point_pleasant
ID: 35039076
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
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:bpatton_psr
ID: 35039564
Didn't work. Saved it as a .bat in the same directory. Ran it. Nothing happens.
0
 
LVL 8

Expert Comment

by:point_pleasant
ID: 35039807
oops this is bash shell for linux machine
0
 

Author Comment

by:bpatton_psr
ID: 35040066
Ah, I am using a Windows machine.
0
 

Author Comment

by:bpatton_psr
ID: 35044899
Hey. I wasn't sure if you were writing a script for a windows bat file or vbs. Thought I'd check.
0
 

Accepted Solution

by:
bpatton_psr earned 0 total points
ID: 35062086
@echo off 

for /f "tokens=1,2 delims=_" %%a in ('dir *.pdf /b') do ( 
md "%%a" 2>nul 
move "%%a_%%b" ".\%%a\" >nul 
) 
for /f "delims=" %%a in ('dir /a:d /b') do ( 
copy /b "%%a\*.*" "%%a.pdf" 
) 

Open in new window

0
 

Author Closing Comment

by:bpatton_psr
ID: 35115395
Didn't get any response, so got help from different websites. Thought to post the solution here and close the question out.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Simple Linear Regression
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question