I am trying to read two separate awk files and parse the second into an output file.
file1 contains the numbers:
1 2 5 7 10
file2 contains a header (number of fields <3) and data values ββin columns (25 columns)
_rlnNrOfSignificantSamples #24 _rlnMaxValueProbDistribution #25 300.000000 25425.970703 25000.669922 6.050000 2.000000 56.000000 0.277790 79096.000000 0.100000 000001@Particles /Micrographs/006_particles.mrcs 453.000000 604.000000 1.000000 0.859382 Micrographs/006.mrc 1 -3.469177 -3.469177 0.000000 0.000000 -82.345885 23 9475.876495 1 0.988689 300.000000 25425.970703 25000.669922 6.050000 2.000000 56.000000 0.277790 79096.000000 0.100000 000002@Particles /Micrographs/006_particles.mrcs 431.000000 428.000000 1.000000 0.806442 Micrographs/006.mrc 1 -1.469177 -3.469177 0.000000 0.000000 87.654115 22 9412.959278 1 1.000000
I want to read the numbers from file1 into an array, and then:
- print header from file2
- print lines from file2 if the values ββin the $ 22 field are NOT in the array (in the example earlier, its values ββare 23 and 22)
After one day of struggle, I came up with the following:
#!/bin/bash FieldNum=22 awk -vf=$FieldNum 'FNR==NR{num[$1]; next} { # print the header of file2 if(NF < 3) {print > "output"} # check lines after header else {if (f in num) {} else {print >> "output"}} }' $file1 $file2
But it turns out that all lines from file2 are printed, so checking the array does not work. Could you please indicate my mistake?
source share