Copying specified columns

Help with writing and playing macros

Copying specified columns

Postby BigAl » Mon Jul 26, 2004 11:14 pm

I need a macro that can copy selected columns from a file (column numbers 267 to 278) and paste into a new empty file. Shouldn't be too difficult right? I just can't work out the syntax for this program. Thanks.
User avatar
BigAl
Newbie
 
Posts: 3
Joined: Mon Jul 26, 2004 11:00 pm

Re: Copying specified columns

Postby Mofi » Fri Jul 30, 2004 8:25 am

After selecting the columns execute following macro:

InsertMode
ColumnModeOn
HexOff
UnixReOff
Copy
NewFile
Paste

Or do you want that the macro selects the column first. That would be more difficult, but can also be solved with a few tricks.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4064
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Copying specified columns

Postby BigAl » Mon Aug 02, 2004 9:20 pm

Is there a command to select columns 267 to 278 that I could put in front of the code you have suggested.

(the Ultraedit equivalent to columns(267:278).select)

This would allow me to open the files and run the macro without manually selecting the columns.

Thanks Al.
User avatar
BigAl
Newbie
 
Posts: 3
Joined: Mon Jul 26, 2004 11:00 pm

Re: Copying specified columns

Postby Mofi » Tue Aug 03, 2004 2:43 am

UE has no macro command to go or select a specified column. So cursor moves are needed in the macro to do that.

First, I don't know, if the first line of your files have always at least 267 characters. If so, you can use Macro 2, which does not modify the source file. Macro 1 inserts a line with 267 spaces at the top of the source file. You have to expand the Replace command of Macro 1 with additionally 266 spaces before ^p.

After setting the cursor to column 267 with one of these methods, column mode is activated and everything to the end of file is selected. Because I don't know if your files end with a linefeed, the macro sets the cursor to column 1 of the last line.

Now 278 Key RIGHT ARROW are necessary in both macros to set the cursor to column 278 of the last line while selection mode is still active. Insert in both macros additionally 277 Key RIGHT ARROW.

The correct columns are now selected and copied to the new file.

In Macro 1 the inserted line with spaces is removed in the source and new file. So the data in the new file is correct and the source file is modified but has the exact content before execution of the macro.

Macro 1
InsertMode
ColumnModeOff
HexOff
UnixReOff
Top
Find RegExp "%^(*^)$"
Replace " ^p^1"
Top
Key END
ColumnModeOn
StartSelect
SelectToBottom
Key HOME
Key RIGHT ARROW
Copy
EndSelect
ColumnModeOff
Top
StartSelect
Key DOWN ARROW
EndSelect
Key DEL
NewFile
Paste
Top
StartSelect
Key DOWN ARROW
EndSelect
Key DEL

Macro 2
InsertMode
ColumnModeOff
HexOff
UnixReOff
Top
Loop
Key RIGHT ARROW
IfColNum 267
ExitLoop
EndIf
EndLoop
ColumnModeOn
StartSelect
SelectToBottom
Key HOME
Key RIGHT ARROW
Copy
EndSelect
ColumnModeOff
Top
NewFile
Paste
Top
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4064
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Copying specified columns

Postby BigAl » Mon Aug 09, 2004 3:09 am

Mofi, Thanks for your help on this, I could not get either of your macros to work but in the process found this code does the trick. It would be nice if it 'copied' rather than 'cut' from the source file but I can live with that.

Cheers,
Al.

ColumnModeOn
GotoLine 3
Loop 266
Key RIGHT ARROW
EndLoop
ColumnCut 11
ColumnModeOff
NewFile
Paste
ColumnModeOn
Top
User avatar
BigAl
Newbie
 
Posts: 3
Joined: Mon Jul 26, 2004 11:00 pm


Return to Macros