HyperNext Studio
HyperNext Studio => General => Topic started by: lenitech on March 29, 2011, 07: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
-
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)
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.