0

I have two input files like these:

file1

ABC001;text;text;5.00;text;text;;20/06/2020;http://www.domain.com/img/foobar4325.jpg
ABC002;text;text;15.20;text;text;;4/12/2021;http://www.domain.com/img/foobar545.jpg
ABC003;text;text;10.00;text;text;;24/07/2021;http://www.domain.com/img/foobar6y6.jpg
ABC004;text;text;4.90;text;text;;31/12/2021;http://www.domain.com/img/foobar5464.jpg
ABC007;text;text;10.30;text;text;;3/12/2021;http://www.domain.com/img/foobar45tgv.jpg
ABC010;text;text;9.00;text;text;;20/12/2021;http://www.domain.com/img/foobar2345f.jpg

file2 ("rounded" prices are without .00)

ABC001;text;text;6
ABC002;text;text;15.20
ABC003;text;text;10
ABC004;text;text;5.50
ABC005;text;text;25
ABC007;text;text;10.50
ABC010;text;text;9

output desired:

ABC001;text;text;5.00;text;text;;20/06/2020;http://www.domain.com/img/foobar4325.jpg
ABC004;text;text;4.90;text;text;;31/12/2021;http://www.domain.com/img/foobar5464.jpg
ABC007;text;text;10.30;text;text;;3/12/2021;http://www.domain.com/img/foobar45tgv.jpg

The rows need to match the first column and then compare matched rows "price" column (fifth) it the price is numerically different I would like to extract only the the rows from the file1.

I use this (GNU Awk 4.0.2):

awk -F';' -v RS='[\r\n]+' 'FNR==NR{righe[$1]; next} $1 in righe' file1.csv file2.csv > output.csv

to compare two csv file but I'm not able to add the price conditional

0

1 Answer 1

2

You just need to pick the right columns and also first read the file2 then file1, additionally you also need to compare the value part as well as well as the key part:

awk -F';' 'NR==FNR{ id[$1]=$4; next} ($1 in id) && id[$1]!=$4' file2 file1

here $1 is used for the keys of the array id and $4 are the value part.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .