[awk] working with two files

Hello guys,
I have little to no experience working with two files in awk and hope you can help me with a problem that may be easy for you to solve...

awk -v cut1="$var1" -v cut2="$var2" '{split($0, arr1); for(i=1;i<=NF;i++) if (arr1 < cut1) print arr1, NR, i}' file1 file2

The above code is the basis for what I need to do. I have two cutoffs cut1 and cut2 that I read into awk and two files with the same number of columns and lines.

I need to check a condition if (arr1 [i]< cut1) for every element of file1 and if it is true check the same element in file2 for another condition. If both conditions prove true then I need to print out the elements of both files, as well as line and field number.

Am I making any sense here or should I choose an alternative route to a solution? :cool:

Thanks for any help!

I think you should post sample input data and desired output.

cutoffs:

cut1=1.00000
cut2=5.00000

file1

3.75289 3.72466 3.72257
3.45011 3.43072 3.44495
3.27445 3.25306 3.27761
3.0973 3.06597 3.09548
2.76982 0.55555 2.76169
2.83836 2.80111 2.81722
2.71083 2.65765 2.66011
2.77565 2.7335 2.67739
2.96274 2.91895 2.88512
2.93073 2.8461 2.89448

file2

1.1154    0.0141    0.0234
0.0198    0.0258    0.0230
0.0126    0.0214    0.0174
0.0115    0.0143    0.0246
0.0146    9.9999    0.0149
0.0128    0.0143    0.0157
0.0114    0.0158    0.0152
0.0109    0.0248    0.0149
0.0116    0.0211    0.0216
0.0304    0.0247    3.3209

desired output:

value1: 9.9999 | value2: 0.55555 |  line: 5 | column: 2

output should only be printed if both conditions are met, e.g.: 0.55555 < cut1 and 9.9999 > cut2

Try:

paste file1 file2 | awk -v cut1="$var1" -v cut2="$var2" '{for (i=1;i<=3;i++){if($i<cut1&&$(i+3)>cut2){print "value1:",$(i+3),"| value2:",$i,"| line:",NR,"| column:",i}}}'
1 Like

great idea bartus, thanks... this way it works generally for me!

paste file1 file2 | awk -v cut1="$var1" -v cut2="$var2" '{for (i=1;i<=NF/2;i++){if($i<cut1&&$(i+NF/2)>cut2){print "value1:",$(i+NF/2),"| value2:",$i,"| line:",NR,"| column:",i}}}'