printf について助けが必要です。
現在私はこのスクリプトを持っています
awk '{c[$1"\t"$7]++}END{for(x in c)if (c[x]>10){printf "from %s (%d)\n",x,c[x]}}' /checkip.log >> bb.log
それは私に
from 120.230.xx.xxx /index (16)
from 120.231.xx.xxx /index (16)
from 120.236.xx.xxx /index (16)
等々。
checkip.log
各行の先頭/末尾に、現在の Linux サーバーの時刻 (日付ではなく) を印刷したいと思います。
例えば
[07/Mar/2020:20:00:04 +0000] from 120.230.xx.xxx /index (16)
[07/Mar/2020:20:00:04 +0000] from 120.231.xx.xxx /index (16)
[07/Mar/2020:20:00:04 +0000] from 120.236.xx.xxx /index (16)
答え1
GNU awkをお持ちの場合は
awk 'BEGIN{ d=strftime("[%d/%b/%Y:%H:%M:%S %z]") }
{c[$1"\t"$7]++}
END{for(x in c)if (c[x]>10){printf "%s from %s (%d)\n",d,x,c[x]}}' /checkip.log >> bb.log
GNU awkをお持ちでない場合は、
awk -vd="$(date '+[%d/%b/%Y:%H:%M:%S %z]')" '{c[$1"\t"$7]++}
END{for(x in c)if (c[x]>10){printf "%s from %s (%d)\n",d,x,c[x]}}' /checkip.log >> bb.log
挿入する文字列を計算するための日付を取得します。
標準の免責事項、日、月、名前、年、時間、分、秒は、結果を単純に並べ替えたい場合には適切な選択ではありません。年、月、日、時間、分、秒を検討してください。