Find and replace data in a specific text field

Help with writing and playing macros

Find and replace data in a specific text field

Postby Hunter » Thu Aug 10, 2006 3:06 pm

Hi New to this macro game, hope someone can help plz.

I have a text file with around 5000 lines. I will use the example below to explain what I am upto....

I am trying to find lines starting with AA then to look at column 50 and replace the 01 with 00

Before

AA 01
AB 01

After

AA 00
AB 00


Any ideas?

Thank-you

Hunt
User avatar
Hunter
Newbie
 
Posts: 3
Joined: Wed Aug 09, 2006 11:00 pm

Re: Find and replace data in a specific text field

Postby Mofi » Fri Aug 11, 2006 5:40 am

I don't understand your example. Is only column 50 (or 51) of the line starting with AA set to 0 or also all following lines because AB line has also changed to 00.

If only 01 in the line starting with AA must be set to 00, it can be done without a macro with following UltraEdit style regular expression replace:

Find: %^(AA???????????????????????????????????????????????^)01
Replace: ^100
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4039
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Find and replace data in a specific text field

Postby Hunter » Fri Aug 11, 2006 7:32 am

Hi thanks for the reply, sry the first example it was not great...


I am looking for multiple strings.

I wish to change for example the 01s when AA or AB is found at the start of the line. In reality I am going to be looking for about 50 combinations, so i believe a macro with a loop would help(problem is I dont have the skills to write one :cry: ).

Before

AA 01
AA 01
AA 01
AA 01
AB 01
AB 01
AB 01

After

AA 00
AA 00
AA 00
AA 00
AB 00
AB 00
AB 00


Not sure what the ultra edit style is either........... omg

Many thanks for your help
8O
User avatar
Hunter
Newbie
 
Posts: 3
Joined: Wed Aug 09, 2006 11:00 pm

Re: Find and replace data in a specific text field

Postby Mofi » Fri Aug 11, 2006 9:10 am

See Advanced - Configuration - Search - Regular Expression Engine which engine/style you use for regular expression searches and replaces.

The following macro solution needs the macro property Continue if a Find with Replace not found checked.

You can read in my second post at multiple files conversions help how to create a new macro and paste the following code into it.

InsertMode
ColumnModeOff
HexOff
UnixReOff
Top
Find MatchCase RegExp "%^(AA???????????????????????????????????????????????^)01"
Replace All "^100"
Find MatchCase RegExp "%^(AB???????????????????????????????????????????????^)01"
Replace All "^100"
... and so on for all your combinations

Add UnixReOn or PerlReOn (v12+ of UE) at the end of the macro if you do not use UltraEdit style regular expressions by default - see search configuration. Macro command UnixReOff sets the regular expression option to UltraEdit style.

Well, the 2 regex above could be also combined to a single one:

Find MatchCase RegExp "%^(A[AB]???????????????????????????????????????????????^)01"
Replace All "^100"

See help of UltraEdit about the Find command and the Regular expressions to understand these regular expressions.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4039
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Find and replace data in a specific text field

Postby Hunter » Sat Aug 12, 2006 3:29 pm

Thank you....

Worked a treat :P

Excellent Work
User avatar
Hunter
Newbie
 
Posts: 3
Joined: Wed Aug 09, 2006 11:00 pm


Return to Macros