Now I have to compare file A and B based on the integer part of column 3. Means first 2 rows should be OK and the third row should not satisfy the criteria. First two columns make a unique row in one file so no row will be repeated in a file. Same first two columns will be in both the files....means if we can build a logic to compare the integer part of third column for each row (based on column 1 and 2). Thanks.
Actually in my case column 1 and column 2 also have dot(.) so this command is not returning correct values. I have to compare on column 3 only. My files are as follows:
I tried this one and it returns
I have tried this but it does not work on actual code. I have sent you one line of real data in your private message and this code fails even if you make both the files same.
$
$
$ cat filea
Mechanical.Markdown.Directed.POS.$ WK17 10.5
$
$ cat fileb
Mechanical.Markdown.Directed.POS.$ WK17 10.5
$
$ ## show the contents of these files with ^I for TAB characters and $ for end-of-line
$ cat -et filea
Mechanical.Markdown.Directed.POS.$^IWK17^I10.5$
$
$ cat -et fileb
Mechanical.Markdown.Directed.POS.$^IWK17^I10.5$
$
$
$ ## now try the awk script, tweaked a little bit so that it displays a message for lines that match
$ awk -F"\t" 'NR==FNR {x[NR]=$0}
NR!=FNR {split(x[FNR],a,"\t");
if(int(a[3]) != int($3)) {printf("ROW %d\n< %s\n---\n> %s\n",FNR,x[FNR],$0)}
else {print "ROW ",FNR,"is the same in both files"}
}' filea fileb
ROW 1 is the same in both files
$
$
$
$ ## now try the other case - edit one file so that the last field is different
$
$ sed 's/10.5/11.5/' filea >tmp && mv tmp filea
$
$ ## check the contents of both files again
$ cat filea
Mechanical.Markdown.Directed.POS.$ WK17 11.5
$
$ cat fileb
Mechanical.Markdown.Directed.POS.$ WK17 10.5
$
$ ## finally, try the awk script once again
$ awk -F"\t" 'NR==FNR {x[NR]=$0}
NR!=FNR {split(x[FNR],a,"\t");
if(int(a[3]) != int($3)) {printf("ROW %d\n< %s\n---\n> %s\n",FNR,x[FNR],$0)}
else {print "ROW ",FNR,"is the same in both files"}
}' filea fileb
ROW 1
< Mechanical.Markdown.Directed.POS.$ WK17 11.5
---
> Mechanical.Markdown.Directed.POS.$ WK17 10.5
$
$
If your results are different, then my best guess is that either one or both the files aren't truly tab-delimited.
Check the octal dump of each file to see what exactly is in there.