Jump to content
Macro Express Forums

Reverse Text File Order


Asm0deus

Recommended Posts

Hello everyone.

 

I been away from the macex world for about 6months and trying to work on an old macro of mine.

 

I can't remember how to go about reversing the output of one text file into another.

 

TextFileA TextFileB

 

123456 012345

234567 567890

345678 456789

456789 345678

567890 234567

012345 123456

 

The number of entries will be anywhere from 5-100 so I cant assign which slot to start on. Im pretty embarrsed I dont remember how to do this. Someone give me a hand?

Link to comment
Share on other sites

Here is one way to do it:

// Set CR/LF
Variable Set %T13% to ASCII Char of 013
Variable Set %T10% to ASCII Char of 010
Replace "%T13%" with "%T13%%T10%" in %T13%

// Set input and output files
Variable Set String %T10% "c:\temp\test.txt"
Variable Set String %T11% "c:\temp\out.txt"

// Count lines in the input file
Variable Set Integer %N1% to 0
Text File Begin Process: "%T10%"
 Variable Modify Integer: Inc (%N1%)
Text File End Process

// Create a text variable of lines from input file (last-to-first)
Variable Set String %T9% ""
Repeat Start (Repeat %N1% times)
 Text File Begin Process: "%T10%"
   Variable Modify String: Append "%T1%%T13%" to %T9%
 Text File End Process
Repeat End

// Copy text variable to output file
Variable Modify String: Save %T9% to Text File
Macro Stop


<REM2:Set CR/LF><ASCIIC:13:1:013><ASCIIC:10:1:010><TMVAR2:21:13:00:000:000:%T13%%T13%%T10%><REM2:><REM2:Set input and output files><TVAR2:10:01:c:\temp\test.txt><TVAR2:11:01:c:\temp\out.txt><REM2:><REM2:Count lines in the input file><IVAR2:01:01:0><BTFBEG:001:000001:000000:%T10%><NMVAR:08:01:0:0000001:0:0000000><BTFEND><REM2:><REM2:Create a text variable of lines from input file (last-to-first)><TVAR2:09:01:><REP3:01:%N1%:0000-1:%N1%:1:02:><BTFBEG:001:N00002:000001:%T10%><TMVAR2:07:09:00:000:000:%T1%%T13%><BTFEND><ENDREP><REM2:><REM2:Copy text variable to output file><TMVAR2:17:09:00:000:000:%T11%T><MSTOP>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...