here my intension is to list all data from file1.txt and print text "not available" to data which is not available in reference.txt
output looks like this
9 72.92 available
9.75 72.77 available
10.57 72.75 available
10.53 73 available
10.43 73.5 available
10.33 74 available
9.97 76 available
11.95 88 not available
11.83 89 not available
12.55 84 not available
12.42 85 not available
12.27 86 not available
11.82 89 not available
Thanks pamu its working will you please explain..suppose files contains different number of columns say file1.txt contains 5 columns reference.txt contains 10 columns then
Yes it won't work in that case. Because our matching criteria as $0 itself won't work here.
As per our matching pattern we can have arrays. Assume column 1 and 2 from file1.txt and column 2 and 5 from reference.txt. and print file1.txt.
Then we can use sth like this..
9 72.92 available
9.75 72.77 available
10.57 72.75 available
10.53 73 available
10.43 73.5 available
10.33 74 available
9.97 76 available
11.95 88 not available
11.83 89 not available
12.55 84 unmatched reference file
12.42 85 unmatched reference file
Are there duplicate lines in file1?
If not, you can delete Av [i]just before the break, and in an END section print out the remaining Av entries.
If yes, you need a second array indexed like Av to hold the fact of a match, and then, in the END section, print out the Av elements that do not have a "match" entry.
yes, there are some records in file1.txt, which are same as that of reference file.
script works fine as per my requirement, but for some other purpose I want to print unmatched records in reference file also along with file1.txt
Thank you for your reply I will try.
---------- Post updated at 05:45 AM ---------- Previous update was at 02:56 AM ----------
Pamu will you please help me to implement #7 in your script
awk 'NR==FNR{A[$0]=$0; next} # Here we read reference.txt file and store it in array A with index as $0.
{print A[$0]?A[$0] FS "available" : $0 FS "not available"; # Here we check $0 is available or not in Array A. If $0 is present then print as available or not available.
delete A[$0] } # Here for those who are availabe delete those records from Array.
END{for (i in A){if(A){print A,"unmatched reference file"}}}' # Here print those records which is not present in file1.txt