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.
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.
Comments