awk -v tstamp="$(date -d "-30 days" +%s)" ' # Pass the date minus 30 days as variable to awk (tstamp)
/install/ || /upgrade/ { # Process where lines
contain install or
upgrade
dconv=gensub("-"," ","g",$1); # Replace "-" for " " in
the first space
delimited field (date)
and read result into
dcon
tconv=gensub(":"," ","g",$2); # Replace ":" for " " in
the second space
delimited field (time)
and read the result
into tconv
dstamp=mktime(dconv" "tconv); # Create epoch format of
date and time
if (dstamp >= tstamp ) { # See whether date/time
is within 30 days by
comparing dstamp to
tstamp
print # Print line if
condition is met
}
}' /var/log/dpkg.log
2条答案
按热度按时间js4nwp541#
示例输出:
yi0zb3m42#
Awk是一个理想的解决方案(GNU awk利用了gensub函数)
说明: