From e8e926759fe566a755538d540bf945b8c9e6d0b0 Mon Sep 17 00:00:00 2001 From: "Bujue.Win10" Date: Thu, 17 Feb 2022 11:53:00 +0800 Subject: [PATCH] =?UTF-8?q?match=E5=B9=B6=E9=87=8D=E5=AE=9A=E5=90=91?= =?UTF-8?q?=E8=87=B3=E6=96=B0=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logDataClean.awk | 56 ++++++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/logDataClean.awk b/logDataClean.awk index 9f8fc8e..8f8ba4c 100644 --- a/logDataClean.awk +++ b/logDataClean.awk @@ -7,48 +7,52 @@ ############################# 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) - dp_recv_from_device = @/ dp rept_type:[0-9]+, data:{/ - dp_is_condition = @/dp [0-9]+ match/ - dp_not_condition = @/no [0-9]+ match/ - pattern = @/([0-9]+-[0-9]+ ([0-9]+:){3}[0-9]+)/ - - connection_check_ok = @/condition set is ok,then execute action set./ + #dp_recv_from_device = @/ dp rept_type:[0-9]+, data:/ + #dp_is_condition = @/dp [0-9]+ match/ + #dp_not_condition = @/no id match/ + #pattern = @/([0-9]+-[0-9]+ ([0-9]+:){3}[0-9]+)/ +# + #connection_check_ok = @/condition set is ok,then execute action set./ # Get form OS } -!a++{ -} -$0~dp_recv_from_device{ - matchRet(/[0-9]{1,2}-[0-9]{1,2} ([0-9]{1,2}:){3}[0-9]{1,3}/); -} -$0~dp_is_condition{ +$0~/ dp rept_type:[0-9]+, data:/ { + 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; + adps = match($0,/\{.+\}/) ? substr($0,RSTART,RLENGTH):null; + 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{ } function matchRet(reg ,RSTART,RLENGTH){ - if(match($0,$reg)){ return substr($0,RSTART,RLENGTH) }else{ return "Nothing Matched" } -} - -function maker_Json(){ - 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":matchRet(/\{.+\}/) + #print reg + if(match($0,$reg)){ + return substr($0,RSTART,RLENGTH) + }else{ + return "Nothing Matched" } } -function write2file(){ - echo $1 >> $filePath +function maker_Json(){ + 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"}" +} + +function write2file(maker_Json){ + system("echo "maker_Json" >> $filePath") } \ No newline at end of file