Board logo

标题: 比较两个文本文件是否相同 [打印本页]

作者: bobo247     时间: 2008-3-11 10:31    标题: 比较两个文本文件是否相同

有两个文本文件,想要比较他们是否相同,比较的对象以行为单位。这两个文件的行号可以不一样,只要行的内容一样,就可以判定相同。把结果输出来,相同或者不同的字样,在dos屏幕上反映出来。
比如说:
作者: bobo247     时间: 2008-3-11 10:36
不如说
文件1.txt里面的行是:
   1234||abc||CC
   0987||bnsc||txt
  oquigh||bnvgh||yox

文件2.txt里面的行是:
  oquigh||bnvgh||yox
  1234||abc||CC
  0987||bnsc||txt

要判断这两文件相等如何做,请大虾指教
作者: 5872169     时间: 2008-3-11 10:47
FC命令,查询FC /?
作者: bobo247     时间: 2008-3-11 10:52
小弟是初学者,请详细地说
作者: bat-zw     时间: 2008-3-11 12:37
代码如下:
@echo off
fc 1.txt 2.txt
if errorlevell o goto show/此句即为判断两文件大小是否相同,是就转向show标签。
go to :eof
:show
echo 这两个文件大小一样
goto :eof

[ Last edited by zw19750516 on 2008-3-11 at 12:41 PM ]
作者: fastslz     时间: 2008-3-11 13:35
真晕~
日复一日的~重复话题
搜索
作者: plp626     时间: 2008-3-11 14:05
批处理弄这个太差了,
只知道findstr做这个还行,但是行太长了(>127个字符)就不行了
比较两个文件内容,将不同的行显示出来:
findstr /vg:1.txt 2.txt

作者: HAT     时间: 2008-3-11 14:15
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\>fc /?
Compares two files or sets of files and displays the differences between
them


FC [/A] [/C] [/L] [/LBn] [/N] [/OFF[LINE]] [/T] [/U] [/W] [/nnnn]
   [drive1:][path1]filename1 [drive2:][path2]filename2
FC /B [drive1:][path1]filename1 [drive2:][path2]filename2

  /A         Displays only first and last lines for each set of differences.
  /B         Performs a binary comparison.
  /C         Disregards the case of letters.
  /L         Compares files as ASCII text.
  /LBn       Sets the maximum consecutive mismatches to the specified
             number of lines.
  /N         Displays the line numbers on an ASCII comparison.
  /OFF[LINE] Do not skip files with offline attribute set.
  /T         Does not expand tabs to spaces.
  /U         Compare files as UNICODE text files.
  /W         Compresses white space (tabs and spaces) for comparison.
  /nnnn      Specifies the number of consecutive lines that must match
             after a mismatch.
  [drive1:][path1]filename1
             Specifies the first file or set of files to compare.
  [drive2:][path2]filename2
             Specifies the second file or set of files to compare.
作者: suntb     时间: 2008-3-11 18:58
@echo off
sort 1.txt>>t1.txt
sort 2.txt>>t2.txt
fc t1.txt t2.txt /n
pause