Compare numbers in two text documents and print out if the difference is too big

crystal

I got two text files with following structure. A number then some spaces and the path to a file.

--- File 1 ---
1198464 ./aaa/file_A
   6345 ./bbb/file_B
  24345 ./bbb/file_C
2345212 ./ccc/file_D
  92315 ./ddd/file_E
 852217 ./ddd/file_F

--- File 2 ---
1198464 ./aaa/file_A
   1234 ./bbb/file_B
  24340 ./bbb/file_C
 452217 ./ddd/file_F

Now I want to compare those two files and print out ONLY the file names that exists in BOTH documents AND where the number got a bigger difference than "8". In the above case, following should be printed out:

file_B
file_F

file_C will not be printed out because the difference between 24345 and 24340 is less than 8.

Raman Sailopal
awk -F[\/.] 'NR==FNR { map[$NF]=$1 } NR!=FNR { gsub(" ","",$1);if ((map[$NF] -$1)>8) { print $NF }  }' File1 File2

Set the field separator to / or . Process File1 first (NR==FNR) Create an array (map) with the last field (NF - file name) as the index and the size the value. Then for the second file (NR!=FNR) remove any spaces with gsub and then when the difference in size is greater than 8, print the last field (file name)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Compare Two Dictionaries and Print Difference

Compare two int arrays and print the missing numbers

Compare two dictionaries and print out missing or no matches

compare two excel sheet and print the difference?

compare two lists in python and print the difference

How to compare two list and print the difference number

Compare two files with different numbers, but with same text

I want to compare 2 files in AIX and print the difference in numbers

Python compare text from first column of two documents

Compare two documents

React Text Too Big

hitbox of text too big

How to compare two numbers in a line which are not same in length and print them

Python : Compare two csv files and print out differences

Compare two String[] arrays and print out the strings which differ

Compare two list with dicts and print out value that is not in the list using Python?

Compare two lists and print out when a change happens

Perl (compare two file) print out differences on main file only

Compare two arrays and print out Index of row in python

Compare two log files line by line and print difference

Panda - Compare Two Dataframes - Verify INT difference and print

Python - compare two string by words using difflib and print only difference

How do I print out a list of common factors for two numbers?

How do I compare one text file against about two dozen other text files and print out certain columns of each line whenever there is a match?

Error when compare big numbers

How to compare two dictionary key values and print text in cell in iOS?

Compare two files and print results to new text file

Difference of two big files

jq Compare two files and output the difference in text format