Question

Using DCL, i have a .txt file with 3 lines

Line 1 test.
Line 2 test.
Line 3 test.

I'm trying to very that each contains exactly what is expected. I'm currently using the f@extract function which will give me the output of line 1 but i cannot figure out how to verify line 2 and 3. What function can i use to make sure lines 2 and 3 are correct?

$ OPEN read_test test.dat
$ READ/END_OF_FILE=ender read_test cc
$ line1 = f$extract(0,15,cc)
$ if line1.nes."Line 1 test."
$ then
$    WRITE SYS$OUTPUT "FALSE"
$ endif
$ line2 = f$extract(??,??,cc)  ! f$extract not possible for multiple lines?
$ if line2.nes."Line 2 test."
$ then
$    WRITE SYS$OUTPUT "FALSE"
$ endif
Was it helpful?

Solution

For exactly 3 line you might just want to do 3 reads and 3 compares...

$ READ READ/END_OF_FILE=ender read_test cc
$ if f$extract(0,15,cc).nes."Line 1 test." ...
$ READ READ/END_OF_FILE=ender read_test cc
$ if f$extract(0,15,cc).nes."Line 2 test." ...
$ READ READ/END_OF_FILE=ender read_test cc
$ if f$extract(0,15,cc).nes."Line 3 test." ...

Any more and you want to be in a loop as replied. TO follow up on Chris's approach, you may want to first prepare an array of values and then loop reading and comparing as long as there are values. Untested:

$ line_1 = "Line 1 test."
$ line_2 = "Line 2 test."
$ line_3 = "Line 3 test."
$ line_num = 1
$ReadNext:
$   READ/END_OF_FILE=ender read_test cc
$   if line_'line_num'.nes.cc then WRITE SYS$OUTPUT "Line ", line_num, " FALSE"
$   line_num = line_num + 1
$   if f$type(line_'line_num').NES."" then GOTO ReadNext
$ WRITE SYS$OUTPUT "All provided lines checked out TRUE"
$ GOTO end
$Ender:
$ WRITE SYS$OUTPUT "Ran out of lines too soon. FALSE"
$end:
$ close Read_Test

hth, Hein.

OTHER TIPS

Try this variation (untested, so may need a little debugging). Makes use of symbol substitution to keep track of which line you are up to.

$ OPEN read_test test.dat
$ line_num = 1
$ ReadNext:
$   READ/END_OF_FILE=ender read_test cc
$   line'line_num' = f$extract(0,15,cc)
$   if line'line_num'.nes."Line ''line_num' test."
$   then
$      WRITE SYS$OUTPUT "FALSE"
$   endif
$   goto ReadNext
$ !
$ Ender:
$ close Read_Test
$ write sys$output "line1: "+line1
$ write sys$output "line2: "+line2
$ write sys$output "line3: "+line3
$ exit
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top