I have a text file shown below:
Doc_A 123 abc
Doc_A 456 def
Doc_A 789 ghi
Doc_B 123 abc
Doc_B 456 def
Doc_C 123 abc
Doc_C 456 def
Doc_C 789 ghi
Doc_C 101 jkl
And a reference file
Doc_A
Doc_B
Doc_C
Doc_D
Doc_E
Doc_F
I want to extract the first line from text file that matches the name in the reference file and print that line and if there is no match print a certain fixed pattern as shown:
Doc_A 123 abc
Doc_B 123 abc
Doc_C 123 abc
Doc_D 10 20
Doc_E 10 20
Doc_F 10 20
I can use awk as shown below to print for matching pattern. How would I print patterns not found, certain fixed way as I require?
awk 'FNR == NR { a[$1] = 0; } FNR != NR { for (i in a) if ($0 ~ i && a[i]++ == 0) { print $0; break; } }' \ref.txt file.txt