I want to get all lines within specified date. The following pattern prints 15/Jan however when used for awk it gives Fatal Unmatched error.
pattern=$(date -d "2 day ago" +'%d/%b')
awk '$4 ~ $pattern' file.txt
I have tried \ to escape the / sign, so far not successful.
$
is completely unrelated operator.$pattern
is actually$0
and will try to get the whole line. Try withawk -v "pattern=$pattern" '$4 ~ pattern' file.txt
instead. – Jan 22 '21 at 05:59