newbie needs help with complicated rename function

A swapping-ground for Regular Expression syntax

newbie needs help with complicated rename function

Postby kasthuri » Wed May 19, 2010 5:23 pm

Hi all I have a series of filenames like the following:

Tile_r3-c3_w12_st01_sec01.tif

The images are taken as a montage of a single optical plan (r3-c3 meaning row 3 column 3 of the montage). They are also multiple sections that correspond to 'z levels'. st01_sec01 means that this montage is taken from strip 01 section 01. The next montage z level would then be st01_sec02. There are ~ 9 sections per strip and then a new strip is started but continues down in z (i.e. st01_sec09 is a 'higher' level than st02_sec01). Each strip is on a wafer that extends in Z as well. (i.e. all of the strips from wafer 12 (w12 above) are higher in z than all the sections from wafer 13). thus, *.w11_st09_sec09 comes just 'before' *.w12_st01_sec01 . I would like to take a sequence like the above and rename it from

Tile_r3-c3_w12_st01_sec01.tif to Tile_Z{zzz}_Y{yyy}_X{xxx}.tif

where Z(zzz) is an absolute number extracted from w*_st*_sec* and Y{yyy} and X{xxx} are rows and columns respectively. I have given a more concrete example below (this assumes that I am starting the z -numbering from w12 but that is not necessarily the case

Tile_r3-c3_w12_st01_sec01.tif Tile_Z{001}_Y{003}_X{003}.tif
Tile_r3-c2_w12_st01_sec01.tif Tile_Z{001}_Y{002}_X{003}.tif
Tile_r3-c1_w12_st01_sec01.tif Tile_Z{001}_Y{001}_X{003}.tif
Tile_r2-c3_w12_st01_sec01.tif Tile_Z{001}_Y{003}_X{002}.tif
Tile_r2-c2_w12_st01_sec01.tif Tile_Z{001}_Y{002}_X{002}.tif
Tile_r2-c1_w12_st01_sec01.tif Tile_Z{001}_Y{001}_X{002}.tif
Tile_r1-c3_w12_st01_sec01.tif Tile_Z{001}_Y{003}_X{001}.tif
Tile_r1-c2_w12_st01_sec01.tif Tile_Z{001}_Y{002}_X{001}.tif
Tile_r1-c1_w12_st01_sec01.tif Tile_Z{001}_Y{001}_X{001}.tif

Tile_r3-c3_w12_st01_sec02.tif Tile_Z{002}_Y{003}_X{003}.tif
Tile_r3-c2_w12_st01_sec02.tif Tile_Z{002}_Y{002}_X{003}.tif
Tile_r3-c1_w12_st01_sec02.tif Tile_Z{002}_Y{001}_X{003}.tif
Tile_r2-c3_w12_st01_sec02.tif Tile_Z{002}_Y{003}_X{002}.tif
Tile_r2-c2_w12_st01_sec02.tif Tile_Z{002}_Y{002}_X{002}.tif
Tile_r2-c1_w12_st01_sec02.tif Tile_Z{001}_Y{001}_X{002}.tif

Etc. I have over 2000 files that need to be renamed this way and I am way lost! Any help (and as always soon :) would be greatly appreciated.

Thanks
BK
kasthuri
 
Posts: 2
Joined: Wed May 19, 2010 5:06 pm

Rename by reordering/dropping/adding parts

Postby Stefan » Wed May 19, 2010 7:54 pm

Hi BK,
welcome.


kasthuri wrote:Hi all I have a series of filenames like the following:

Tile_r3-c3_w12_st01_sec01.tif

The images are taken as a montage of a single optical plan (r3-c3 meaning row 3 column 3 of the montage). They are also multiple sections that correspond to 'z levels'. st01_sec01 means that this montage is taken from strip 01 section 01. The next montage z level would then be st01_sec02. There are ~ 9 sections per strip and then a new strip is started but continues down in z (i.e. st01_sec09 is a 'higher' level than st02_sec01). Each strip is on a wafer that extends in Z as well. (i.e. all of the strips from wafer 12 (w12 above) are higher in z than all the sections from wafer 13). thus, *.w11_st09_sec09 comes just 'before' *.w12_st01_sec01 . I would like to take a sequence like the above and rename it from

Tile_r3-c3_w12_st01_sec01.tif to Tile_Z{zzz}_Y{yyy}_X{xxx}.tif

where Z(zzz) is an absolute number extracted from w*_st*_sec* and Y{yyy} and X{xxx} are rows and columns respectively. I have given a more concrete example below (this assumes that I am starting the z -numbering from w12 but that is not necessarily the case

Tile_r3-c3_w12_st01_sec01.tif Tile_Z{001}_Y{003}_X{003}.tif
Tile_r3-c2_w12_st01_sec01.tif Tile_Z{001}_Y{002}_X{003}.tif
Tile_r3-c1_w12_st01_sec01.tif Tile_Z{001}_Y{001}_X{003}.tif
Tile_r2-c3_w12_st01_sec01.tif Tile_Z{001}_Y{003}_X{002}.tif
Tile_r2-c2_w12_st01_sec01.tif Tile_Z{001}_Y{002}_X{002}.tif
Tile_r2-c1_w12_st01_sec01.tif Tile_Z{001}_Y{001}_X{002}.tif
Tile_r1-c3_w12_st01_sec01.tif Tile_Z{001}_Y{003}_X{001}.tif
Tile_r1-c2_w12_st01_sec01.tif Tile_Z{001}_Y{002}_X{001}.tif
Tile_r1-c1_w12_st01_sec01.tif Tile_Z{001}_Y{001}_X{001}.tif

Tile_r3-c3_w12_st01_sec02.tif Tile_Z{002}_Y{003}_X{003}.tif
Tile_r3-c2_w12_st01_sec02.tif Tile_Z{002}_Y{002}_X{003}.tif
Tile_r3-c1_w12_st01_sec02.tif Tile_Z{002}_Y{001}_X{003}.tif
Tile_r2-c3_w12_st01_sec02.tif Tile_Z{002}_Y{003}_X{002}.tif
Tile_r2-c2_w12_st01_sec02.tif Tile_Z{002}_Y{002}_X{002}.tif
Tile_r2-c1_w12_st01_sec02.tif Tile_Z{001}_Y{001}_X{002}.tif

Etc. I have over 2000 files that need to be renamed this way and I am way lost! Any help (and as always soon :) would be greatly appreciated.

Thanks
BK


I didn't read all of this, i just show you an example, hopping it is right.
Test this with an few test files first.

Depending on your examples:

FROM:
Tile_r3-c3_w12_st01_sec01.tif to
TO:
Tile_Z{"sec01"}_Y{"c3"}_X{"r3"}.tif
dropping "_w12_st01_"



FROM:
Tile_r3-c3_w12_st01_sec01
TO:
Tile_Z{001}_Y{003}_X{003}

Do:
RegEx(1)
Search: (.+_)r(\d)-c(\d)_w12_st01_sec(\d\d)
Replac: \1Z{0\4}_Y{00\3}_X{00\2}






Explanation:
for
Tile_r3-c3_w12_st01_sec01
the regex
(.+_)r(\d)-c(\d)_w12_st01_sec(\d\d)
means:

(.+_) >> match one-or-more of any sign till next expression "r" >>>> will match "Tile_" and is grouped
             in group (...) one, which can be accessed by \1 in the replacement.
r(\d) >> match literally "r" followed by one digit and group the regex with (...) parentheses to match the digit , which match the "3" and can be reused by \2
-c(\d) >> match an dash followed by "c", then match one digit in an third group, this "3" can be accessed by \3 in replacement
_w12_st01_ >> match "_w12_st01_" literally , don't group them since we doesn't need them in replacement
sec(\d\d) >> match "sec" followed by two digits, you can use \4 in Replace to access what is matched by this regex \d\d which give you here "01".

(i see now i didn't had needed to group () this "Tile_" too, ... but anyway... it doesn't hurts... so let it be :roll: )

Then compose your replacement string "\1Z{0\4}_Y{00\3}_X{00\2}"
by using the back reference meta chars "\n" where "n" is the number of the wanted (...)-group from the left.
\1 holds "Tile_"
\2 holds "3"
\3 holds "3" too in this example
\4 holds here "01"

So the replacement (new name) is build like that:
\1   +   "Z{0"   +   \4   +   "}_Y{00"   +   \3   +   "}_X{00"   +   \2   +   "}"

in short: "\1Z{0\4}_Y{00\3}_X{00\2}"




HTH? :D
If yes: please help two others too.

General Note:
Always don't trust me! Test with test files first!
My solution depends on the quality of your examples.
The term "RegEx" describes an technique as that (Regular Expressions) and an used expression (like ".+") itself.
In BRU select a few files in the "Name" column to see changes on the "New Name" column.
If i had used "quotes", then don't use them for real, they are only for explanation.
If i had used ~ signs exchange them each by an space/blank.
At the end we build the new name by using that what is matched by the regex inside the parentheses, and build that way our New Name.
That what is matched in Search by the regex in the first (...) parentheses, can be accessed In Replacement by using "\1", and second (...) by \2,...


See this two oldest posts in the Regular Expressions sub-forum for an RegEx syntax overview:
=> Getting Started: http://www.bulkrenameutility.co.uk/forum/viewtopic.php?f=3&t=5
=> Go ahead: http://www.bulkrenameutility.co.uk/forum/viewtopic.php?f=3&t=27


And BTW:
BK> "newbie needs help with complicated rename function"
That's clear, that's normal, that's why you post here, you don't have to use this as subject.
Please think about an better title and modify your post accordingly.
Like "Renaming by moving part" or reorder of parts in file name or like that.
Stefan
 
Posts: 736
Joined: Fri Mar 11, 2005 7:46 pm
Location: Germany, EU

Re: newbie needs help with complicated rename function

Postby kasthuri » Wed May 19, 2010 9:25 pm

First thank you very much for your reply stefan. I have learned the most today by just looking back at your posts and working on the solutions you have given others..incredibly useful and helpful! Your command worked great but I think there is an added wrinkle.

As you see below,

Tile_r3-c3_w12_st01_sec09.tif Tile_Z{001}_Y{003}_X{003}.tif
Tile_r3-c2_w12_st01_sec09.tif Tile_Z{001}_Y{002}_X{003}.tif
Tile_r3-c1_w12_st01_sec09.tif Tile_Z{001}_Y{001}_X{003}.tif
Tile_r2-c3_w12_st01_sec09.tif Tile_Z{001}_Y{003}_X{002}.tif
Tile_r2-c2_w12_st01_sec09.tif Tile_Z{001}_Y{002}_X{002}.tif
Tile_r2-c1_w12_st01_sec09.tif Tile_Z{001}_Y{001}_X{002}.tif
Tile_r1-c3_w12_st01_sec09.tif Tile_Z{001}_Y{003}_X{001}.tif
Tile_r1-c2_w12_st01_sec09.tif Tile_Z{001}_Y{002}_X{001}.tif
Tile_r1-c1_w12_st01_sec09.tif Tile_Z{001}_Y{001}_X{001}.tif

Tile_r3-c3_w12_st02_sec01.tif Tile_Z{002}_Y{003}_X{003}.tif
Tile_r3-c2_w12_st02_sec01.tif Tile_Z{002}_Y{002}_X{003}.tif
Tile_r3-c1_w12_st02_sec01.tif Tile_Z{002}_Y{001}_X{003}.tif
Tile_r2-c3_w12_st02_sec01.tif Tile_Z{002}_Y{003}_X{002}.tif
Tile_r2-c2_w12_st02_sec01.tif Tile_Z{002}_Y{002}_X{002}.tif
Tile_r2-c1_w12_st02_sec01.tif Tile_Z{001}_Y{001}_X{002}.tif

When I finish all the sections in a strip (i.e. st01 to st02 in the case above) I want the numbering to increment from Z{009} to Z{010}. I think in the scrip you provided it would go back to Z{001}. Is there anyway I can use BRU to name the first nine files z{01} the next 9, z{02} and so on...they show up in the right sequence in BRU but I can not do a simple number increment since I wanto group 9 files together...
thank you again for your help!

best
BK
kasthuri
 
Posts: 2
Joined: Wed May 19, 2010 5:06 pm

Re: newbie needs help with complicated rename function

Postby Stefan » Wed May 19, 2010 10:34 pm

Hi.

I have taken the digit for "Z" from original file name, what was wrong, yes?
You want as digit for the "Z{...}" an numbering from 001-009
like Z{001}...Z{009}, then again Z{001}...Z{009} for the next nine files?
(Or as in your last post Z{01}...Z{09})


FROM:
Tile_r3-c3_w12_st01_sec01.tif to
TO:
Tile_Z{"sequence 1 to 9 for each nine files"}_Y{" digit from c"}_X{"digit from r"}.tif
dropping "_w12_st01_" part.


I think this (breaking at nine) is not possible with BRU.

Maybe i know tomorrow more, after an cup of sleep.
Stefan
 
Posts: 736
Joined: Fri Mar 11, 2005 7:46 pm
Location: Germany, EU

Re: newbie needs help with complicated rename function

Postby Stefan » Thu May 20, 2010 9:51 pm

Am i right with my assuming?:
Stefan wrote:TO:
Tile_Z{"sequence 1 to 9 for each group of nine files: 001, 002...009"}_Y{" here digit from c"}_X{"digit from r"}.tif
dropping "_w12_st01_" part.

Is this what you want?


EDIT:
ah, now i see you mean:
TO:
Tile_Z{"001 for the first group of nine files, then 002 for the second group of 9, ... "}_Y{" here digit from c"}_X{"digit from r"}.tif
dropping "_w12_st01_" part.

Right?

160
Stefan
 
Posts: 736
Joined: Fri Mar 11, 2005 7:46 pm
Location: Germany, EU


Return to Regular Expressions


cron