Am 23.08.2013 11:21, schrieb Sven Schreiber:
Here's my take at doing it in hansl (untested), but let's not forget
that the goal is (IMHO) to make the preprocessing unnecessary
altogether, by enabling 'join' do smaller/greater comparisons on ISO
date strings!
Following is now an actually working version, tested with the real-world
1MB file of INDPRO. However, it is very slow, much slower than using my
Python solution it seems to me. Don't know if there are some gretl
string internals that could be sped up.
cheers,
sven
<hansl>
string temp = readfile(fname)
string out = ""
## Need to roughly guess the number of lines in the file
# The min number of chars per line is 3*10+4+6=40
repetitions = ceil(strlen(temp)/40)
string rest = temp
string col1 = ""
string col2 = ""
string col3 = ""
string col4 = ""
set echo off
loop repetitions # loop over the lines in file
sscanf(rest,"%s\t%s\t%s\t%s\n",col1,col2,col3,col4)
string rest = strstr(rest,"\n") + 1 # offset to drop the leading \n
## do the replacements
# realtime_start_date is the 3rd col
string trans3 = strsub(col3,"-","")
trans3 = strsub(trans3,".","99999999") # or "_latest_"
# and realtime_end_date the 4th
string trans4 = strsub(col4,"-","")
trans4 = strsub(trans4,".","99999999")
## put the stuff together and add to output
sprintf temp "@col1\t@col2\t@trans3\t@trans4\n"
string out += temp
if rest=="" # end of file reached
break
endif
endloop
## write the transformed file
set echo off
outfile @outfname --write
print out
outfile --close
</hansl>