Quantcast
Channel: AWK Command to Select Date Range - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 3

AWK Command to Select Date Range

$
0
0

I would like to monitor the /var/log/secure file for user activity. I need to be able to provide a start date and select lines only occurring after that date . I have played around with awk for a while and have not been able to find a solution that works. I have had some commands that appear to work but just end up selecting every line from the file. In the command below I am trying to select all entries after July 9th, 2019.

cat /var/log/secure* | awk '{d=system("date -d "$1 $2, 2019 $3" +%s"); if ( 1562731201 < d );  print}'
awk: cmd. line:1: {d=system("date -d "$1 $2, 2019 $3" +%s"); if ( 1562731201 > d );  print}
awk: cmd. line:1:                                         ^ 2 is invalid as number of arguments for system

date -d @1562644801
Tue Jul  9 00:00:01 EDT 2019

Any help you can provide would be appreciated.


Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images