Re: Comparing two files line by line



Niv wrote:
I have a stimulus file with 3 digit hex numbers and a results file also
with 3 digit hex numbers (The rtesults file has already gone through
one tcl script to get the results into the same format as the
stimulus).
The results file may be longer than the stimulus file due to default
results once stimulus has expired (This is for a VHDL testbench).

The files are not too long, probably < 100 lines.

So how do I compare the files line by line, until stimulus finished,
then check any extra lines in results are default?

The only way I see is to read each file line by line into two separate
lists & then work on the lists.
I don't think the while { [gets $f1 inline1] >= 0}
{ will work, as how do I get the data-line from $f2?

Is there a simpler way?

TIA, Niv.

If the files are small, it is easier to read the whole thing and then split
by lines.

set buf1 [read $f1]
set buf2 [read $f2]

foreach l1 [split $buf1 "\n"] l2 [split $buf2 "\n"] {
if {$l1 eq $l2} {
puts "Lines the same"
} else if {$l1 eq "" && $l2 eq $default} {
puts "default output"
} else {
puts "something else"
}
}

Bruce
.



Relevant Pages

  • Re: What waste exist in the fiscal stimulus plan
    ... Presidents $900 billion stimulus plan. ... $6 billion to turn federal buildings into "green" buildings. ... There are lists of people who will get the "stimulus" money. ... Lots of people who live off government "grants" (scam) are very happy. ...
    (alt.politics)
  • Comparing two files line by line
    ... I have a stimulus file with 3 digit hex numbers and a results file also ... with 3 digit hex numbers (The rtesults file has already gone through ... lists & then work on the lists. ...
    (comp.lang.tcl)