Author Topic: formatting data  (Read 1838 times)

lenitech

  • Newbie
  • *
  • Posts: 3
formatting data
« on: March 29, 2011, 06:52:14 AM »
I would like to write a script that will read a text file with thousands of lines of data and rearrange the data to a different format and save it in the new format.  for example:

Source data format:
x       y      z
12     13    14
7       8      9

New data format:
z       x       y
14     12    13
9       7      8

I have been playing around with the array functions, but I am getting frustrated at the lack of documentation.  This seems like it should be an easy task.  Please help.

-Rob
« Last Edit: January 01, 1970, 12:00:00 AM by Guest »

Malkom

  • Administrator
  • Newbie
  • *****
  • Posts: 395
  • Here to help you
Re: formatting data
« Reply #1 on: March 29, 2011, 01:54:23 PM »
Quote from: "lenitech"
I would like to write a script that will read a text file with thousands of lines of data and rearrange the data to a different format and save it in the new format.  for example:

Source data format:
x       y      z
12     13    14
7       8      9

New data format:
z       x       y
14     12    13
9       7      8

I have been playing around with the array functions, but I am getting frustrated at the lack of documentation.  This seems like it should be an easy task.  Please help.

-Rob

Perhaps you could avoid using arrays and just read each line in, process it, then save it to the new file - here is some code using the simple text file commands (the files are expected to be in the DataTexts folder)

Code: [Select]
Local fend,fname1,h1,sdata
Local fname2,h2

@ --- Open source file ---
Put 'testdata1.txt' into fname1
OpenTRead(fname1,h1)

@ --- Open dest file ---
Put 'testdata2.txt' into fname2
OpenTWrite(fname2,h2)

@ --- Red in file ---
Put EndTFileFN(h1) into fend
While fend=0
    @ read line
    ReadTLine(h1,sdata)

    @ ++++ process line - actually just put into field 1 +++
    Put sdata After field 1

    @ save line
    WriteTLine(h2,sdata)

    @ check if file done
    Put EndTFileFN(h1) into fend
EndWhile

@ --- Close files ---
CloseTRead(h1)
CloseTWrite(h2)

If you need to use a file in a different place you could use the FileGet command and just use its file handle in the above code

http://http://tigabyte.com/forums/viewtopic.php?f=22&t=14


If you need to use arrays then the project BooksHN might be useful as it uses arrays to store its data.
« Last Edit: January 01, 1970, 12:00:00 AM by Guest »
I am sorry but I do not have time to answer questions by PM or email.
If you post your questions in this forum then it might help others.

 

anything