match并重定向至新文件

This commit is contained in:
Bujue.Win10 2022-02-17 11:53:00 +08:00
parent 8bc5498df0
commit e8e926759f
1 changed files with 30 additions and 26 deletions

View File

@ -7,48 +7,52 @@
############################# #############################
BEGIN{ BEGIN{
filePath=/data/log/myJsonLog filePath = "/data/log_dir/mySimpleLog"
# system("echo '\n\n\n----------' >> "awk_run_log_path" && date '+%x %X' >> "awk_run_log_path) # system("echo '\n\n\n----------' >> "awk_run_log_path" && date '+%x %X' >> "awk_run_log_path)
dp_recv_from_device = @/ dp rept_type:[0-9]+, data:{/ #dp_recv_from_device = @/ dp rept_type:[0-9]+, data:/
dp_is_condition = @/dp [0-9]+ match/ #dp_is_condition = @/dp [0-9]+ match/
dp_not_condition = @/no [0-9]+ match/ #dp_not_condition = @/no id match/
pattern = @/([0-9]+-[0-9]+ ([0-9]+:){3}[0-9]+)/ #pattern = @/([0-9]+-[0-9]+ ([0-9]+:){3}[0-9]+)/
#
connection_check_ok = @/condition set is ok,then execute action set./ #connection_check_ok = @/condition set is ok,then execute action set./
# Get form OS # Get form OS
} }
!a++{
} $0~/ dp rept_type:[0-9]+, data:/ {
$0~dp_recv_from_device{ atime = match($0,/[0-9]{1,2}-[0-9]{1,2} ([0-9]{1,2}:){3}[0-9]{1,3}/) ? substr($0,RSTART,RLENGTH):null;
matchRet(/[0-9]{1,2}-[0-9]{1,2} ([0-9]{1,2}:){3}[0-9]{1,3}/); adps = match($0,/\{.+\}/) ? substr($0,RSTART,RLENGTH):null;
}
$0~dp_is_condition{
newjson = "{ \"time\":"atime", \"event\":\"dp report\", \"dps\":"adps"}"
system("echo -e '"newjson"' >> /data/log_dir/mySimpleLog")
} }
$0~connection_check_ok{ # $0~/dp [0-9]+ match/{
} # }
# $0~/condition set is ok,then execute action set\./ {
# aruleid = substr(matchRet(/scene:[0-9a-zA-Z]+\b/),7)
# print aruleid
# }
END{ END{
} }
function matchRet(reg ,RSTART,RLENGTH){ function matchRet(reg ,RSTART,RLENGTH){
if(match($0,$reg)){ return substr($0,RSTART,RLENGTH) }else{ return "Nothing Matched" } #print reg
if(match($0,$reg)){
return substr($0,RSTART,RLENGTH)
}else{
return "Nothing Matched"
}
} }
function maker_Json(){ function maker_Json(){
return { return "{ \"time\":"matchRet(/[0-9]{1,2}-[0-9]{1,2} ([0-9]{1,2}:){3}[0-9]{1,3}/)", \"event\":"matchRet()", \"value\":"matchRet()", \"dps\":"adps"}"
"time":matchRet(/[0-9]{1,2}-[0-9]{1,2} ([0-9]{1,2}:){3}[0-9]{1,3}/),
"event":matchRet(),
"value":matchRet(),
"dps":matchRet(/\{.+\}/)
}
} }
function write2file(){ function write2file(maker_Json){
echo $1 >> $filePath system("echo "maker_Json" >> $filePath")
} }