简体   繁体   中英

compare files in shell script and delta

I have 1 file name file1.txt

cat file1.txt

|    6|        10|
|    7|        20|
|    8|        41|
|   10|        40|
|   11|        40|
|   12|        50|
|   13|        70|
|   15|        80|

cat file2.txt:

|    6|        10|
|    7|        30|
|    8|        81|
|   10|        90|
|   11|        60|
|   12|         0|
|   13|        70|
|   15|        80|

I have to compare these 2 file and with each column I to get info as delta in both file for values should not exceed 5, example: for file 1 : 6 | 10 6 | 10 , for file2 6 | 10 6 | 10 , but for next value 7 | 20 7 | 20 in file 1 and for file 2 it is 7| 30 7| 30 ,

So my target is to find difference between these 2 files and if delta is higher print result of that.

Could some one guide me in this.

I don't fully understand what you mean by "higher" but here is a good starting point

join file1.txt file2.txt  -j 2 -t "|"  | sed -e 's/|//g' | awk '{print $1,$2,$3,$2-$3}'

6 10 10 0
7 20 30 -10
8 41 81 -40
10 40 90 -50
11 40 60 -20
12 50 0 50
13 70 70 0
15 80 80 0

Basically, I merged the 2 files using key as first column and then do some processing at the end with awk. Let us know what you want with the final data so we can try to help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM