Linux下两个文件,我想把文件b中第10列(已标出)部分与a第5列(已标出)相同的行输出,怎么操作? 255
#include<stdio.h>
#define N 256
int 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;
}
我看不太懂。。。可不可以用awk或者grep做出来呀
你说的不用编程,用grep指令比较?可查此指令用法完成,这里是编程频道