フォーラム: 公開討議 (スレッド #40525)

discarding unwanted lines of text read by teraterm (2019-03-13 13:25 by wayne_1964 #82703)

Hi,
I am trying to write a TerraTerm Language script to read configuration data from a text file and send it a piece of equipment. I am not worried about the ip/serial port side of the script.
My issue is there is a lot of data in the config files that I do not need to send as they are not needed in our application.
Also , currently I am simply writing the config commands to another text file . However all the lines of text come out double spaced , and there is a gap where the unwanted lines of text would be.
I believe the script is seeing a new line character at the end of each line of text read from the config file and is sending this to the output file as a separate line.

an example of the config file vs the output is shown below

;orignal config.txt file

$WMO="xxxxx"
$Hmsl=1079.6
$LAT=999.999
LONG=999.999
$UTCadj=+10:00
$DSoffset=3600

output file
$WMO="xxxxx"

$Hmsl=1079.6

$LAT=999.999

$LONG=999.999

$UTCadj=+10:00

$DSoffset=3600

the code below sort of deals with this , but only by writing the unwanted blank lines to another file, same with the unwanted text which contain the sub-string 'asc'


dest_file ='destination.txt '
asc_file = 'asc.txt'
:main
call prep
call upload
exit
:prep
inputbox 'Please enter the directory path where the xxx config file is located' 'Input Directory'
config_dir = inputstr
foldersearch config_dir
if result=1 then
setdir config_dir
inputbox 'please enter the config file name ( including the .txt extension)' 'Filename'
config_file = inputstr
filesearch config_file
if result =1 then
messagebox 'file found' 'FILE FOUND'
else
messagebox 'file not found' 'FILE NOT FOUND'
endif
else
messagebox 'folder not found' 'FOLDER NOT FOUND'
endif
return
:upload
filecreate dest dest_file
filecreate asc_txt asc_file
fileopen asc_txt asc_file 0
fileopen dest dest_file 0
fileopen config config_file 0
filereadln config param
while result = 0
strscan param 'asc'
if result > 0 then
filewriteln asc_txt param
else
strlen param
if result <2 then
filewriteln asc_txt param
else
filewriteln dest param
endif
endif
filereadln config param
loop
fileclose dest
fileclose asc_txt
return


Can anyone suggest a better way to do this , how do you discard a line of text you don't want and move to the next line from the config file?
Also how do i get rid of the newline character at the end of each line in the config.txt file ( you can see them in word).
There are several hundred files available to upload, so it i snot a simple task to go and edit them individually, especially when they are stored on different platforms across Australia

Thanks in advance

Wayne
Obviously I am really NOT much at writing scripts