Macro to copy data from one file to another

Help with writing and playing macros

Macro to copy data from one file to another

Postby Onkel_Tom » Sun Aug 29, 2004 8:07 pm

Hi all,
I use UltraEdit since 2 years and find no better editor than UltraEdit in the Internet ;-)
So my problem is that I'm not able to work with macros because I'm not understanding the function.

I want to export data from a textfile to another Textfile for import in a MySQL database but all my tries and test didn't work. So it would be very nice if someone can help me with the correct macro.

The first files contain about 350 Spider datasets like this one:
Code: Select all
robot-id: gromit
robot-name: Gromit
robot-cover-url: http://www.austlii.edu.au/
robot-details-url: http://www2.austlii.edu.au/~dan/gromit/
robot-owner-name: Daniel Austin
robot-owner-url: http://www2.austlii.edu.au/~dan/
robot-owner-email: dan@austlii.edu.au
robot-status: development
robot-purpose: indexing
robot-type: standalone
robot-platform: unix
robot-availability: none
robot-exclusion: yes
robot-exclusion-useragent: Gromit
robot-noindex: no
robot-host: *.austlii.edu.au
robot-from: yes
robot-useragent: Gromit/1.0
robot-language: perl5
robot-description: Gromit is a Targetted Web Spider that indexes legal
 sites contained in the AustLII legal links database.
robot-history: This robot is based on the Perl5 LWP::RobotUA module.
robot-environment: research
modified-date: Wed, 11 Jun 1997 03:58:40 GMT
modified-by: Daniel Austin


The second file should read:
Code: Select all
(no., 'robot-name', 'robot-useragent', 'robot-cover-url', 'robot-details-url', 'robot-owner-name', 'robot-owner-url', 'robot-platform', 'robot-language', 'robot-description', '', 'images/statistik/spider/robot-name.gif', 'images/statistik/barx.gif', 0),


Instead of the Names e.g. "robot-description" the data from the first textfile after the ":" should be copied in the second file.
no. should be a counter beginning from 1, and barx.gif should be a counter beginning from 1 to 11 and then beginning again from 1-12 and so on.

no. and also barx.gif can be done manually from hand but the data from about 350 robots description to copy to a second file in that format should be done from a macro.

Any Idea how to code that ?

thanks in advance
Tom
User avatar
Onkel_Tom
Newbie
 
Posts: 2
Joined: Sat Aug 28, 2004 11:00 pm

Re: Macro to copy data from one file to another

Postby Mofi » Tue Oct 26, 2004 9:44 am

Here is the mega macro for reformating your data. Remove the green comments, which are just for better understandig, what the macro does.

I have not really understood the numbering of barx.gif. The macro numbers it bar1.gif, bar2.gif, ..., bar12.gif, bar1.gif, bar2.gif, ..., bar12.gif, bar1.gif, .... Hope, this is what you want.

Tip for all users writing big macros: Do it step by step. Every comment was a stand-alone developed and testet macro on the execution result of the macros before. Replace the comments by command "ExitMacro" to see what is really going on during execution and remove ExitMacro step by step.

InsertMode
ColumnModeOff
HexOff
UnixReOff
Comment: Copy whole file to new file
SelectAll
Copy
EndSelect
Top
NewFile
Paste
Comment: Make sure, that last line is an empty line and trim trailing spaces.
Bottom
IfColNum 1
Else
"
"
EndIf
Top
TrimTrailingSpaces
Comment: Remove unwanted data.
Find RegExp "%robot-id*^p"
Replace All ""
Find RegExp "%robot-owner-email*^p"
Replace All ""
Find RegExp "%robot-status*^p"
Replace All ""
Find RegExp "%robot-purpose*^p"
Replace All ""
Find RegExp "%robot-type*^p"
Replace All ""
Find RegExp "%robot-availability*^p"
Replace All ""
Find RegExp "%robot-exclusion*^p"
Replace All ""
Find RegExp "%robot-exclusion*^p"
Replace All ""
Find RegExp "%robot-noindex*^p"
Replace All ""
Find RegExp "%robot-host*^p"
Replace All ""
Find RegExp "%robot-from*^p"
Replace All ""
Find RegExp "%robot-history*^p"
Replace All ""
Find RegExp "%robot-environment*^p"
Replace All ""
Find RegExp "%modified-date*^p"
Replace All ""
Find RegExp "%modified-by*^p"
Replace All ""
Comment: Convert multi-line descriptions to single-line descriptions.
Find "robot-description"
IfFound
Key HOME
Key DOWN ARROW
Loop
IfCharIs 32
Key BACKSPACE
Key HOME
Key DOWN ARROW
Else
Find "robot-description"
IfFound
Key HOME
Key DOWN ARROW
Else
ExitLoop
EndIf
EndIf
EndLoop
EndIf
Top
Comment: Reformat data with only 1 search and replace.
Find RegExp "robot-name:[ ]++^(*^)^probot-cover-url:[ ]++^(*^)^probot-details-url:[ ]++^(*^)^probot-owner-name:[ ]++^(*^)^probot-owner-url:[ ]++^(*^)^probot-platform:[ ]++^(*^)^probot-useragent:[ ]++^(*^)^probot-language:[ ]++^(*^)^probot-description:[ ]++^(*^)^p"
Replace All "(000, '^1', '^7', '^2', '^3', '^4', '^5', '^6', '^8', '^9', '', 'images/statistik/spider/^1.gif', 'images/statistik/barx.gif', 0),^p"
Top
Comment: Numbering lines.
Key RIGHT ARROW
ColumnModeOn
SelectToBottom
StartSelect
Key Ctrl+END
Key Ctrl+RIGHT ARROW
Key Ctrl+RIGHT ARROW
Key Ctrl+RIGHT ARROW
Key Ctrl+RIGHT ARROW
Key Ctrl+UP ARROW
ColumnInsertNum 1 1 LeadingZero
ColumnModeOff
Top
EndSelect
Comment: Numbering barx.gif.
Loop
Find MatchCase "barx.gif"
IfFound
Key LEFT ARROW
Key LEFT ARROW
Key LEFT ARROW
Key LEFT ARROW
Key BACKSPACE
"1"
Else
ExitLoop
EndIf
Find MatchCase "barx.gif"
IfFound
Key LEFT ARROW
Key LEFT ARROW
Key LEFT ARROW
Key LEFT ARROW
Key BACKSPACE
"2"
Else
ExitLoop
EndIf
Find MatchCase "barx.gif"
IfFound
Key LEFT ARROW
Key LEFT ARROW
Key LEFT ARROW
Key LEFT ARROW
Key BACKSPACE
"3"
Else
ExitLoop
EndIf
Find MatchCase "barx.gif"
IfFound
Key LEFT ARROW
Key LEFT ARROW
Key LEFT ARROW
Key LEFT ARROW
Key BACKSPACE
"4"
Else
ExitLoop
EndIf
Find MatchCase "barx.gif"
IfFound
Key LEFT ARROW
Key LEFT ARROW
Key LEFT ARROW
Key LEFT ARROW
Key BACKSPACE
"5"
Else
ExitLoop
EndIf
Find MatchCase "barx.gif"
IfFound
Key LEFT ARROW
Key LEFT ARROW
Key LEFT ARROW
Key LEFT ARROW
Key BACKSPACE
"6"
Else
ExitLoop
EndIf
Find MatchCase "barx.gif"
IfFound
Key LEFT ARROW
Key LEFT ARROW
Key LEFT ARROW
Key LEFT ARROW
Key BACKSPACE
"7"
Else
ExitLoop
EndIf
Find MatchCase "barx.gif"
IfFound
Key LEFT ARROW
Key LEFT ARROW
Key LEFT ARROW
Key LEFT ARROW
Key BACKSPACE
"8"
Else
ExitLoop
EndIf
Find MatchCase "barx.gif"
IfFound
Key LEFT ARROW
Key LEFT ARROW
Key LEFT ARROW
Key LEFT ARROW
Key BACKSPACE
"9"
Else
ExitLoop
EndIf
Find MatchCase "barx.gif"
IfFound
Key LEFT ARROW
Key LEFT ARROW
Key LEFT ARROW
Key LEFT ARROW
Key BACKSPACE
"10"
Else
ExitLoop
EndIf
Find MatchCase "barx.gif"
IfFound
Key LEFT ARROW
Key LEFT ARROW
Key LEFT ARROW
Key LEFT ARROW
Key BACKSPACE
"11"
Else
ExitLoop
EndIf
Find MatchCase "barx.gif"
IfFound
Key LEFT ARROW
Key LEFT ARROW
Key LEFT ARROW
Key LEFT ARROW
Key BACKSPACE
"12"
Else
ExitLoop
EndIf
EndLoop
Top
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4051
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna


Return to Macros