【发布时间】:2020-08-11 09:16:32
【问题描述】:
与我之前的帖子类似,我正在尝试以下操作:
Myfile.txt 包含:
$TTL 600
@ IN SOA dns1.mysite.com. root.localhost. (
2020042101 ; serial
1h ; refresh
30m ; retry
1w ; expiry
30m) ; minimum
IN NS localhost.
dns1.mysite.com IN A 172.16.1.18
dns2.mysite.com IN A 172.16.2.18
; Redirect this site to localhost to block
; List last consolidated on 12/11/2018
; DNS Blocks
*.mad IN CNAME *.
beans.com A 127.0.0.1 ; this is a test case
*.000webhostapp.com A 127.0.0.1
*.00h5.com A 127.0.0.1
*.00webhostapp.com A 127.0.0.1
myscript.sh 包含:
date=$ (date '+%y%m%d'01)
ydate=$ (date -d yesterday '+%y%m%d'01)
awk "{sub(/$ydate/,$date)}1" myfile.txt > tempt.txt && mv temp.txt myfile.txt
就目前而言,如果文件中的日期仅与昨天的日期匹配,则此方法有效。我现在要做的是匹配昨天或之前的日期,如果是,则将其替换为 $date,然后覆盖文件。
我知道 awk 可以使用“n1 -le n2”来做到这一点,但我无法让它与我正在使用的操作内联工作。
谁能帮我解决这个问题?
谢谢!
【问题讨论】: