2013-02-07 27 views
0

具體線路使用DCL,我有3條線DCL驗證DCL

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

我想非常每個包含正是預計.txt文件。我正在使用f @ extract函數,它會給出第1行的輸出,但是我不知道如何驗證第2行和第3行。我可以使用什麼函數來確保第2行和第3行是正確的?

$ 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 
+0

>> $ OPEN read_test test.dat。免費諮詢?打開前放置一個$ CLOSE/NOLOG read_test。如果您在測試過程中或者在沒有完成測試的情況下放棄測試程序,那麼OPEN將被忽略,因爲文件仍處於打開狀態,並且讀取將繼續,在剩下的地方可能會成爲第一個問題6次。乾杯,海因。 – Hein

回答

2

對於你可能只想做3讀取和3比較準確3線...

$ 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." ... 

任何更多,你想在一個循環的回答。 爲了跟進Chris的方法,您可能需要先準備一組值,然後循環讀取和比較,只要有值。 未經測試:

$ 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 

心連心, 海因。

1

試試這個變化(未經測試,所以可能需要一點調試)。使用符號替換來跟蹤您所處的行。

$ 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