#158073 - 2006-03-02 02:55 AM
Is there a better way to deal with data in a text file?
|
IanDubbelboer
Fresh Scripter
Registered: 2004-06-25
Posts: 24
|
I need some advice from the Kixtart sages.
I am writting a script that does some automated backups to CD and in the course of doing so, I write a log file that looks like this:
Code:
****************************************************************** Results of Backup_for_IDubbelboer_on_January_15_2006 ******************************************************************
The backup of files took 0:03:31 to complete.
The following files, if any, were skipped as they were in use.
The compression and encryption of the backup file took 0:19:21 to complete.
The splitting of the compressed backup file took 0:02:26 to complete. The file was split into 2 parts.
It took 0:03:00 to burn the 2 CD(s). CD 1 took 0:00:40 to burn. CD 2 took 0:02:20 to burn.
Backup completed successfully on 2006/01/15
Now I have to read data out of this file at a later date and on a different computer, so I have some code that looks like this:
Code:
$ = OPEN(1,"c:\backup\backup.log",2)
DO
$DoExit = @ERROR $LogRead = READLINE(1)
SELECT
CASE (NOT INSTR($LogRead, " on ") = 0) AND (NOT $OSInfo[1] = 2) $BackupDate = SUBSTR($LogRead, 34, 10)
CASE (NOT INSTR($LogRead, " bytes") = 0) $BackupSpace = SUBSTR($LogRead, 1, (INSTR($LogRead, " bytes") - 1)) $BackupTime = SUBSTR($LogRead, (LEN($LogRead) - 20), 8)
CASE (NOT INSTR($LogRead, "e backup file t") = 0) $CompEncryptTime = SUBSTR($LogRead, 55, 8)
CASE (NOT INSTR($LogRead, "d backup file t") = 0) $SplitTime = SUBSTR($LogRead, 49, 8)
CASE (NOT INSTR($LogRead, "t took") = 0) $CDBurnTime = SUBSTR($LogRead, 8, 8) $CDBurnCount = SUBSTR($LogRead, 29, 1)
CASE 1
ENDSELECT
This code works great, but now I have to be able to support both French and English log files.
With my current technique, I am forced to write another case statement with the correct values to read from a French text file. I also have to write code to make sure I detect the language of the text file before I read it.
So does anyone have a better way of handling this?
Keeping in mind these requirements:
1. Output has to be written to and read from a unicode text file. (If you don't know how to work with unicode, don't worry I can adjust an ascii solution.)
2. Has to be user friendly as non techies will be reading the file as well.
Anyone worked through this kind of problem before?
|
|
Top
|
|
|
|
#158075 - 2006-03-02 07:54 AM
Re: Is there a better way to deal with data in a text file?
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11634
Loc: Space
|
Quote:
Output has to be written to and read from a unicode text file
Well I tend to agree with Shawn in that the .INI file on Windows XP does support Unicode characters. Notepad may not display them correctly but they will be correct in a full blown editor or DOS console. This format will much more easily support all types of languages and very easy to maintain.
Code:
$Backup = ReadProfileString(@ScriptDir+'\'+'BACKUPS.INI', 'BACKUP', 'Temp') 'Values are: ' + $Backup ?
Code:
[BACKUP] Temp=à â ç é è ê ë î ï ô û ù ü
French alphabet From Wikipedia, the free encyclopedia http://en.wikipedia.org/wiki/French_alphabet
|
|
Top
|
|
|
|
#158077 - 2006-03-02 02:42 PM
Re: Is there a better way to deal with data in a text file?
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
Heres another concept - when you create the report, you include an INI section at the bottom of the report - and replicate the details in a machine-readable format. Kinda like this:
Code:
****************************************************************** Results of Backup_for_IDubbelboer_on_January_15_2006 ******************************************************************
The backup of files took 0:03:31 to complete.
The following files, if any, were skipped as they were in use.
The compression and encryption of the backup file took 0:19:21 to complete.
The splitting of the compressed backup file took 0:02:26 to complete. The file was split into 2 parts.
It took 0:03:00 to burn the 2 CD(s). CD 1 took 0:00:40 to burn. CD 2 took 0:02:20 to burn.
Backup completed successfully on 2006/01/15
[Data] Language=English CDBurnTime=0:03:31 CDBurnCount=2
Then in your script, just read the stuff and the language wouldn't matter.
Code:
break on
$Profile = ".\file.rpt"
$CDBurnTime = ReadProfileString($Profile,"Data","CDBurnTime") $CDBurnCount = ReadProfileString($Profile,"Data","CDBurnCount")
?"time=" $CDBurnTime ?"count=" $CDBurnCount
exit 0
Just throwing the idea out there - not sure if I would personally take this approach or not.
|
|
Top
|
|
|
|
#158078 - 2006-03-03 01:00 AM
Re: Is there a better way to deal with data in a text file?
|
IanDubbelboer
Fresh Scripter
Registered: 2004-06-25
Posts: 24
|
Thanks for the input. 
I'm not sure what I'm going to settle on yet, but I came up with another possible idea.
In this script I have a messaging function. Basically, I CALLMESSAGE($MESSAGENUMBER, $LANGUAGE, $VAR1, $VAR2...) and then use the result to correctly show a message to the screen or to a log file.
I was thinking I might be able to call the message function to generate predefined search strings that I could look for. I could use a | instead of passing a $VAR and then use split on the resulting message INSTR to figure out where the Variable would be in the string regardless of language. It should also make things more resistent to changes to the wording in my translation file as I would not have to update the log reader function every time I changed wording.
I still have to try it, but even if it doesn't work the INI ideas should. Thanks again.
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 1644 anonymous users online.
|
|
|