match并重定向至新文件
This commit is contained in:
parent
8bc5498df0
commit
e8e926759f
|
@ -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")
|
||||
}
|
Loading…
Reference in New Issue