Ignoring decimal in comparision

HI All,

I am having a requirement on ignoring mismatch on 2 file

File 1:
  A,B,US,10.02
 A,B,US,10.02
 A,B,US,11.02
File 2:
 A,B,US,10.02
 A,B,US,10.00
 A,B,US,12.02

Here I want to ignore the decimal . If I do diff it is showing File1 AND File2 are different.If I ignore the decimal it is matching.

Thanks in advance

<PLEASE IGNORE FOUND THE SOLUTION>

Hello arunkumar_mca,

Good that you have posted and informed us that you have found the solution. I would like to suggest you that in these cases you could do 2 things.

1st: Add "solved" TAG in POST(see TAGS section of any post) so that people will understand that OP has found solution.

2nd: If you yourself is finding the solution(which is good), try to post it in a thread of same post so that all could be aware of it and could learn from it.

Keep learning and keep posting :b:

Thanks,
R. Singh

2 Likes

bash and ksh can do process substitution:

diff <(cut -f1 -d. file1) <(cut -f1 -d. file2)

Everything after a dot is cut off, before it's handed to diff.
Or more general, cut decimals from *all* numbers:

diff <(sed 's/\([0-9]\)\.[0-9]*/\1/g' file1) <(sed 's/\([0-9]\)\.[0-9]*/\1/g' file2)
1 Like