1

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.

  • 1
    awk doesn't know about shell variables, and in awk, `$` is completely unrelated *operator*. `$pattern` is actually `$0` and will try to get the whole line. Try with `awk -v "pattern=$pattern" '$4 ~ pattern' file.txt` instead. –  Jan 22 '21 at 05:59
  • Thank you Uncle Billy. This solved – bilig james Jan 22 '21 at 06:42

0 Answers0