Linux中怎么对比两个文件呢
可以用diff命令对比文档内容。[语法]: diff [参数] 文件1 文件2[说明]: 本命令比较两个文本文件,将不同的行列出来-b 将一串空格或TAB 转换成一个空格或TAB-e 生成一个编辑角本,作为ex 或ed 的输入可将文件1 转换成文件2[例子]:diff file1 file2diff -b file1 file2diff -e file1 file2 >edscriptdiff 命令的常用参数a 将所有文件当做文本文件来处理b 忽略空格造成的不同B 忽略空行造成的不同q 只报告什么地方不同,不报告具体的不同信息H 利用试探法加速对大文件的搜索i 忽略大小写的变化l 用pr对输出进行分页r 在比较目录时比较所有的子目录s 两个文件相同时才报告v 在标准输出上输出版本信息并退出实例:比较两个文件代码如下:[root@localhost test3]# diff log2014.log log2013.log----------------------------------------------------------------------------3c3《 2014-03---》 2013-038c8《 2013-07---》 2013-0811,12d10《 2013-11《 2013-12----------------------------------------------------------------------------说明:上面的“3c3”和“8c8”表示log2014.log和log20143log文件在3行和第8行内容有所不同;“11,12d10”表示第一个文件比第二个文件多了第11和12行。
linux中怎么用if比较两个文件之间有重复的
#include<stdio.h>#define N 256int main() { char *p,buffer[256],str1[N][20],str[20],str2[20]; FILE *fp; int n,i;if ( fp=fopen("data1.txt","r") ) {n=0;while ( !feof(fp) ) {fgets(buffer,255,fp);sscanf(buffer,"%s%s%s%s%s%s%s",str,str,str,str,str1[n],str,str);n++; if ( n>=N ) break;}fclose(fp);
} else printf("Cannot open data1.txt\n")
;if ( fp=fopen("data2.txt","r") ) {while ( !feof(fp) ) {fgets(buffer,255,fp);sscanf(buffer,"%s%s%s%s%s%s%s%s%s%s%s%s%s%s", str,str,str,str,str,str,str,str,str,str,str,str2,str,str);p=str2; while ( *p ) p++; p--; *p=0;for ( i=0;i<n;i++ ) if ( strcmp(str1[i],str2+1)==0 ) puts(buffer); }fclose(fp);
} else printf("Cannot open data2.txt\n");return 0;}

