1.

Solve : extract string from file to variable?

Answer»

I wish to extract a date/time string from a text file into a variable which I can test against the current MACHINE date/time.

Can this be done in DOS or is VB a better bet?Quote from: gavinkuit on November 11, 2009, 11:23:07 AM

Can this be done in DOS or is VB a better bet?
SHOW what you want to do, with SAMPLE file examples and output text file line 3 looks similar to this:

abcde dd/mm/yyyy hh:mm:ss

I want to extract the date/time and compare it against current machine time so that if machine time is greater I can call another program.handling date is a chore using DOS(cmd.exe), its better if you learn to use vbscript. Check my sig for vbscript tutorial link. Inside, you can look up various Date functions. While you are at that, if you are not restricted, you can download GAWK for windows(ALSO my sig) and try this script.

Code: [Select]BEGIN{
now=systime()
}
NR==3{
strdate=$(NF-1);strtime=$NF
m=split(strdate,d,"/")
n=split(strtime,t,":")
thedate = d[3]" "d[2]" "d[1]" "t[1]" "t[2]" "t[3]
if ( mktime(thedate) > now ){
print "file date greater than system date"
}else{
print "system date greater than file date"
cmd="mycmd args1 args2" # put you command and arguments here.
system(cmd)
}

}
save the above as myscript.awk and on command line
Code: [Select]c:\test> gawk.exe -f myscript.awk file


Discussion

No Comment Found