I use this command directly on our redhat linux server 8.8 and it's working correctly and I get the result I want:
grep '01-FEB-2024' /u01/app/server1/listener_scan/trace/listener_scan.log | awk '{ if ( $NF != 0 ) print $0 }'
I need to automotize this procedure with a bash file and it looks like that it doesn't get the value of current_date variable:
#!/bin/bash
current_date=$(date "+%d-%b-%Y")
grep '$current_date' /u01/app/server1/listener_scan/trace/listener_scan.log | awk '{ if ( $NF != 0 ) print $0 }' >> y.out
grep "$current_date" /u01/app/server1/listener_scan/trace/listener_scan.log | awk '{ if ( $NF != 0 ) print $0 }' >> y.out
grep $current_date /u01/app/server1/listener_scan/trace/listener_scan.log | awk '{ if ( $NF != 0 ) print $0 }' >> y.out
In all of these cases it return an empty value. Thank you in advance.
date "+%d-%b-%Y"
will return06-Feb-2024
, not06-FEB-2024
, so consider usinggrep -i
for case insensitivity – Panki Feb 06 '24 at 14:10