Select and Copy to Multiple Lines

Help with writing and playing macros

Select and Copy to Multiple Lines

Postby Leviticus » Fri Nov 10, 2006 8:47 am

I have a file that contains multiple records ending with the text "START". I am looking for a way to perform a conditional select and paste if the line or lines below contain a 4-digit year at the end of the record. All fields are fixd length.

Data Before:

Afield1 Afield2 Afield3 START
2005
2006
Bfield1 Bfield2 Bfield3 START
2003
2004
2005
2006
Data After:

Afield1 Afield2 Afield3 START
Afield1 Afield2 Afield3 2005
Afield1 Afield2 Afield3 2006
Bfield1 Bfield2 Bfield3 START
Bfield1 Bfield2 Bfield3 2003
Bfield1 Bfield2 Bfield3 2004
Bfield1 Bfield2 Bfield3 2005
Bfield1 Bfield2 Bfield3 2006

I would appreciate any help in writing a macro to perform this function.

Thanks...
User avatar
Leviticus
Newbie
 
Posts: 1
Joined: Fri Nov 10, 2006 12:00 am

Re: Select and Copy to Multiple Lines

Postby Mofi » Fri Nov 10, 2006 3:46 pm

Here is the macro which should do the job. It works with UE v11.20a for an ASCII file with DOS line terminations and configuration option Home Key Always Goto Column 1 checked (important if there are START lines with leading spaces/tabs).

The macro property Continue if a Find with Replace not found must be checked for this macro.

InsertMode
ColumnModeOff
HexOff
UnixReOff
Bottom
IfColNum 1
Else
"
"
EndIf
Top
TrimTrailingSpaces
Clipboard 9
Loop
Find MatchCase RegExp "START$"
IfNotFound
ExitLoop
EndIf
Key Ctrl+LEFT ARROW
StartSelect
Key HOME
Copy
EndSelect
Key DOWN ARROW
StartSelect
Find MatchCase RegExp Select "START$"
IfSel
Key HOME
Else
SelectToBottom
EndIf
Find RegExp "%^([0-9]+^)$"
Replace All SelectText "^c^1"
EndSelect
EndLoop
ClearClipboard
Clipboard 0
Top

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.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4049
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna


Return to Macros

cron