Skip to main content
The 2024 Developer Survey results are live! See the results
$NF+0 not the same as $NF!=0
Source Link
Chris Davies
  • 119.5k
  • 16
  • 164
  • 292

You need to match on a pattern such as 06-FEB-2024, but as was noted in a comment, the date command returns 06-Feb-2024.

You can upper-case the variable:

current_date=$(LC_ALL=C date "+%d-%b-%Y")
grep "${current_date^^}" /u01/app/server1/listener_scan/trace/listener_scan.log |
    awk '{ if ( $NF != 0 ) print $0 }' >> y.out

Also you can merge the combination:

awk -v date="$(LC_ALL=C date +'%d-%b-%Y')" '$0 ~ toupper(date) && $NF+0'$NF!=0' /u01/app/server1/listener_scan/trace/listener_scan.log >>y.out

You need to match on a pattern such as 06-FEB-2024, but as was noted in a comment, the date command returns 06-Feb-2024.

You can upper-case the variable:

current_date=$(LC_ALL=C date "+%d-%b-%Y")
grep "${current_date^^}" /u01/app/server1/listener_scan/trace/listener_scan.log |
    awk '{ if ( $NF != 0 ) print $0 }' >> y.out

Also you can merge the combination:

awk -v date="$(LC_ALL=C date +'%d-%b-%Y')" '$0 ~ toupper(date) && $NF+0' /u01/app/server1/listener_scan/trace/listener_scan.log >>y.out

You need to match on a pattern such as 06-FEB-2024, but as was noted in a comment, the date command returns 06-Feb-2024.

You can upper-case the variable:

current_date=$(LC_ALL=C date "+%d-%b-%Y")
grep "${current_date^^}" /u01/app/server1/listener_scan/trace/listener_scan.log |
    awk '{ if ( $NF != 0 ) print $0 }' >> y.out

Also you can merge the combination:

awk -v date="$(LC_ALL=C date +'%d-%b-%Y')" '$0 ~ toupper(date) && $NF!=0' /u01/app/server1/listener_scan/trace/listener_scan.log >>y.out
Source Link
Chris Davies
  • 119.5k
  • 16
  • 164
  • 292

You need to match on a pattern such as 06-FEB-2024, but as was noted in a comment, the date command returns 06-Feb-2024.

You can upper-case the variable:

current_date=$(LC_ALL=C date "+%d-%b-%Y")
grep "${current_date^^}" /u01/app/server1/listener_scan/trace/listener_scan.log |
    awk '{ if ( $NF != 0 ) print $0 }' >> y.out

Also you can merge the combination:

awk -v date="$(LC_ALL=C date +'%d-%b-%Y')" '$0 ~ toupper(date) && $NF+0' /u01/app/server1/listener_scan/trace/listener_scan.log >>y.out