*! version 2.2 8Nov2017

*! Doug Hemken

Title

file_equal Compare two text files, line by line

Syntax

file_equal basefile using filename
[, options]

Required:
basefile Name of the first file.

filename Name of the second, comparison file.

display Display any differences.

range(#[ #]) Line range to compare.

lines(integer) Number of lines to compare.

except(numlist) Line numbers to NOT compare.

Description

file_equal compares the contents of basefile with filename.
The comparison is done line by line,
i.e. line 1 in basefile against line 1 of filename.

It is possible to compare just a portion of the file(s)
using the range and/or lines options.

You can see the discrepancies between the files by using the
display option.

Options

Required

basename name of the first file. Include the file extension,
i.e. .do, .ado, .txt, or anything else.

filename name of the second file, including the file extension.

Options

display show the discrepancies between files, if any.
This presents the line number
and the complete text in each file at that line.

range(#[ #]) specify a range of lines over which to compare. If
two integers are specified, the comparison will be done over those lines of the files.

If one integer
is specified, the comparison begins at line #.

If one integer is specified along with the lines option, lines # through (# + lines - 1)
are compared.

lines(#) The number of lines to compare - defaults to all lines.
If a complete range is provided (i.e. two
integers) this option is ignored.

except(numlist) The line numbers NOT to compare - the lines otherwise
in the range to skip.

Remarks

Specify lines(#) to compare from the start through line #.

Specify range(#) to compare from line # to the end.

Specify range(# ##) to compare from line # through line ##.

Specify range(#) lines(##) to compare from line # through line # + ## - 1.

Stored results

file_equal stores the following in r():

Scalars
r(equal) 1 if files are the same, 0 otherwise

r(start) line number where comparison starts

r(end) line number where comparison ends

r(lines) number of lines compared

r(differences) number of differences if any

Macros
r(basefile) Name of basefile

r(using) Name of filename

Authors

Doug Hemken

Social Science Computing Cooperative

Univ of Wisc-Madison

dehemken@wisc.edu

https://www.ssc.wisc.edu/~hemken/Stataworkshops

https://github.com/Hemken/file_equal

based on tex_equal by

Santiago Garriga

Facultad de Ciencias Económicas (UNLP - Argentina)

LCSPP - World Bank