Compare File 1 vs File2 and print line no. for difference record and column no of difference present in file2.
比較文件1與文件2和打印行號。對於差異記錄和file2中存在的差異列。
In file1:
在file1中:
User_ID First_name Last_name Address Postal_code
User_1 fistname Lastname 35, Park Lake, California 32068
user2 Johnny Depp 32, Park Lake, California
user3 Tom Cruise 5322 Otter Lane Middleberge 32907
user4 Leonardo DiCaprio Half-Way Pond, Georgetown 1230
user5 Sylvester Stallone 6762,33 Ave N,St. Petersburg 33710
user6 Srleo Stallone 6762,33 Ave N,St. Petersburg 33700
and
和
In file2:
在file2中:
User_ID First_name Last_name Address Postal_code
User_1 fistname Lastname 35, Park Lake, California 32068
user2 Johnny Depp 32, NEW Street, California 96206
user30 Tom Cruise 5322 Otter Lane Middleberge 32907
user4 Leonardo DiCaprio' Half-Way Pond, Georgetown 00000
user5 Sylvester Stallone 6762,33 Ave N,St. Petersburg 33710
user7 Nicolas Cage 55010
user6 Srleo Stallone 6762,33 Ave N,St. Petersburg 33700
**Expected Result:-
**預期結果:-
Difference in file2 is line number followed by column number (where the values do not match)**
file2的差異是行號,后跟列號(值不匹配)**
Line No. 2 COLUMN NO- 4,5
Line No. 3 COLUMN NO-1
Line No. 4 COLUMN NO 3,5
Line No. 5 COLUNN NO 5
Line No. 6 COLUMN NO 1,2,3,4,5
Note: File size to be compare is in GB and File is tab separated and has more than 400 tab separated column.
注意:要比較的文件大小以GB為單位,文件以制表符分隔,並且具有超過400個制表符分隔列。
I am using-
我在用-
awk 'NR==FNR{Arr[$0]++;next}!($0 in Arr){print FNR}' file1 file2
However, it gives me the line numbers and not the Column Numbers
但是,它給出了行號而不是列號
1 个解决方案
#1
2
this should do, however doesn't match your expected result
這應該做,但是不符合您的預期結果
paste f1 f2 |
awk -F'\t' 'NR==1 {n=NF/2}
{for(i=1;i<=n;i++)
if($i!=$(i+n))
{c=c s i; s=","}
if(c)
{print "Line No. " NR-1 " COLUMN NO " c;
c="";s=""}}'
Line No. 2 COLUMN NO 4,5
Line No. 3 COLUMN NO 1
Line No. 4 COLUMN NO 3,5
Line No. 6 COLUMN NO 1,2,3,4,5
Line No. 7 COLUMN NO 1,2,3,4,5
either you're not comparing line by line or some following some other unwritten spec.
要么你不是逐行比較,要么是一些其他不成文的規范。