我有一个包含以下格式记录的文件:
D20220327,S2927,977,1
D20220328,S2927,977,1
D20220329,S2927,977,1
D20220330,S2927,977,1
D20220331,S2927,977,1
D20220401,S2927,977,1
D20220402,S2927,977,1
D20220403,S2927,977,1
D20220404,S2927,977,1
Run Code Online (Sandbox Code Playgroud)
然而,在应用转换将这些时间移回过去 7 天后,它对于 3 月 28 日至 4 月 3 日的日期不起作用,但相同的代码逻辑在 3 月 27 日和 4 月 4 日运行良好。我不明白为什么这仅在一周内不起作用。这是输出
D20220320,S2927,977,1 -- correct
D20220320,S2927,977,1 -- incorrect
D20220321,S2927,977,1 -- incorrect
D20220322,S2927,977,1 -- incorrect
D20220323,S2927,977,1 -- incorrect
D20220324,S2927,977,1 -- incorrect
D20220325,S2927,977,1 -- incorrect
D20220326,S2927,977,1 -- incorrect
D20220328,S2927,977,1 -- correct
Run Code Online (Sandbox Code Playgroud)
这里使用的逻辑是:
BEGIN {
OFS = FS = ","
}
{
t = mktime(sprintf("%4d %.2d %.2d 00 00 00",
substr($1,2,4),
substr($1,6,2),
substr($1,8,2)));
$1 = substr($1,1,1) …Run Code Online (Sandbox Code Playgroud) 目前我有一个包含如下记录的文件:
D20211011,S0519,306668,1
D20211004,S1600,306668,1
D20211009,S1604,306668,1
D20211010,S1605,306668,1
D20211006,S1610,306668,1
D20211011,S1611,306668,1
Run Code Online (Sandbox Code Playgroud)
假设当前日期是20211011,我需要仅对日期小于当前日期的行应用转换,并且日期为过去的行应更新为当前日期。
在上面共享的示例中,应在第 2 行到第 5 行上进行转换。
D20211004,S1600,306668,1 -> D20211011,S1600,306668,1
D20211009,S1604,306668,1 -> D20211011,S1604,306668,1
D20211010,S1605,306668,1 -> D20211011,S1605,306668,1
D20211006,S1610,306668,1 -> D20211011,S1610,306668,1
Run Code Online (Sandbox Code Playgroud)