Search-Replace, find number replace with number+1

Find, replace, find in files, replace in files, regular expressions

Search-Replace, find number replace with number+1

Postby brschatz » Tue Jun 27, 2006 2:09 am

Hello,

I'm trying to find a somewhat automated way to replace some ASCII date / time fields in a Nikon NEF RAW digital image file. None of the various tools I've tried have gotten it right, but editing the binary file does work.

Is it possible to specify a specific string - such as "xx:xx:xx" - and replace the first "xx" with "xx+1". For example finding "19:00:00" and replacing it with "20:00:00".

Many thanks for any assistance. I've done some work with regex's in Perl before but I don't see a way to "inline script" variables, etc. into the search/replace in UltraEdit.

Brian
User avatar
brschatz
Newbie
 
Posts: 2
Joined: Sun Jun 25, 2006 11:00 pm

Re: Search-Replace, find number replace with number+1

Postby Mofi » Tue Jun 27, 2006 5:38 am

There are 2 problems:

1) Regular expressions cannot be used if a binary file is opened in hex mode.

2) Mathematical operations are not possible in regex.

Solution: Modify the binary file with several Replace In Files. Replace In Files allows you to modify binary files with a regular expression.

Here is the macro in UltraEdit style. Modify the red highlighted strings to your environment. The macro needs the property Continue if a Find with Replace not found checked.

UnixReOff
ReplInFiles RegExp "C:\Temp\" "*.raw" "22^(:[0-5][0-9]:[0-5][0-9]^)"
"23^1"
ReplInFiles RegExp "C:\Temp\" "*.raw" "21^(:[0-5][0-9]:[0-5][0-9]^)"
"22^1"
ReplInFiles RegExp "C:\Temp\" "*.raw" "20^(:[0-5][0-9]:[0-5][0-9]^)"
"21^1"
and so on
ReplInFiles RegExp "C:\Temp\" "*.raw" "01^(:[0-5][0-9]:[0-5][0-9]^)"
"02^1"
ReplInFiles RegExp "C:\Temp\" "*.raw" "00^(:[0-5][0-9]:[0-5][0-9]^)"
"01^1"

The same macro in Unix or Perl style according to the engine you select with the first command:

UnixReOn
ReplInFiles RegExp "C:\Temp\" "*.raw" "22(:[0-5][0-9]:[0-5][0-9])"
"23\1"
ReplInFiles RegExp "C:\Temp\" "*.raw" "21(:[0-5][0-9]:[0-5][0-9])"
"22\1"
ReplInFiles RegExp "C:\Temp\" "*.raw" "20(:[0-5][0-9]:[0-5][0-9])"
"21\1"
and so on
ReplInFiles RegExp "C:\Temp\" "*.raw" "01(:[0-5][0-9]:[0-5][0-9])"
"02\1"
ReplInFiles RegExp "C:\Temp\" "*.raw" "00(:[0-5][0-9]:[0-5][0-9])"
"01\1"

As you can see 23:xx:xx is not changed to 00:xx:xx because a change of day cannot be done.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4066
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Search-Replace, find number replace with number+1

Postby brschatz » Tue Jun 27, 2006 6:27 pm

Thanks for the quick reply!

On a side note, I'm a little jealous that you live in Austria. My wife and I spent two weeks in Germany and Austria on our honeymoon and it was great. There was a monestary a little ways outside Munich call Andechs that had the best beer I've every had anywhere (and I've sampled a few :wink: ). That, Salzburg, and Hallstat in Austria were three of our favorite places we hit.
User avatar
brschatz
Newbie
 
Posts: 2
Joined: Sun Jun 25, 2006 11:00 pm


Return to Find/Replace/Regular Expressions

cron