Two files: data1
Name |formula |no. |dose|days|cost |msg|em|notes Fname-Lname|BXXXT+GG |8262|4 |14 |57.78 | | |sq Fname-Lname|SJXXT+GG |8263|4¾ |14 |105.15| | |IB Fname-Lname|FJDHT+BH,LG,CQC,ZX|8264|5¾ |14 |46.20 | | |IB
data2
10/12/2020|more-data-3456|105.15 10/12/2020|more-data-3456|95.10 11/12/2020|more.data-3456|30.30 14/12/2020|more-data-3456|45.55
I am using the code snippet
awk 'BEGIN {FS = "|" } NR==FNR{a[$6];next} $3 in a {print $0}' data1 data2
To match where a value in $6 of file data1 also occurs in $3 of file data2. Where there is a match print out the whole record ($0) containing the match from file data2. I am expecting:
10/12/2020|more-data-3456|105.15
But I am only getting an output of a blank line. I removed the file separators "|"
using a " "
as replacement the command code worked exactly as expected however really want to preserve the field separator as |
if at all possible . I would like to understand why the addition of a BEGIN block has caused this . Has it caused awk to load an empty array in place of taking data from S6 ? My awk level is just above beginner. Edit: I have also used the -F parameter with the same result, an out put of a blank line . I am using gawk .
awk 'BEGIN {FS = "|" } NR==FNR{a[$6+0];next} $3+0 in a {print $0}' data1 data2
? post also output of the commandfile data[12]
cat -vet
? This shows visually any characters which are non-graphic.