Skip to content

Commit

Permalink
Fix syntax error
Browse files Browse the repository at this point in the history
  • Loading branch information
sheilbronn committed Dec 25, 2022
1 parent 883078c commit 8411fd9
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions mqtt-grep-color
Original file line number Diff line number Diff line change
Expand Up @@ -193,16 +193,17 @@ function compare(s1, s2) {
gsub( /[^[:print:]]/ , "", message )
if ( verbose ) { print "MESSAGE(" isJson "," optimizeJSON "): " message } ## FIXME
if ( isJson && optimizeJSON ) {
message=gensub( /" *: *"/ , "\":\"" , "g", message) # remove any spaces around the JSON colon for text values
message=gensub( /" *:[ ]*(-*[0-9]*[.]*[0-9]*)/, "\":\\1" , "g", message) # remove any spaces around the JSON colon for numeric values
message=gensub( /":([0-9])(, *")/ , "\": \\1\\2", "g", message) # pad any one-digit number with one space for better alignment across messages
message=gensub( /"Time" *:"[0-9T:-]*",/ , "" , "g", message) # eliminate the first "Time" key/value but only if it is followed by a comma
message=gensub( /"([a-zA-Z _]+)" *: *(\[?){/ , "\"XXcyanXX\\1XXcyanXX\":\\2{" , "g", message) # highlight the name of a whole embedded object, e.g. device
message=gensub( /^{ */ , "{" , "g", message) # remove opening space
message=gensub( /" *: *(null|")/ , "\":\\1" , "g", message) # remove any spaces around the JSON colon for text values or null
message=gensub( /" *:[ ]*(-*[0-9]*[.]*[0-9]*)/ , "\":\\1" , "g", message) # remove any spaces around the JSON colon for numeric values
# message=gensub( /":([0-9])(, *")/ , "\": \\1\\2", "g", message) # pad any one-digit number with one space for better alignment across messages
message=gensub( /"Time" *:"[0-9T:-]*",/ , "" , "g", message) # eliminate the first "Time" key/value but only if it is followed by a comma
message=gensub( /"([a-zA-Z _]+)" *: *(\[?){/ , "\"XXcyanXX\\1XXcyanXX\":\\2{" , "g", message) # highlight the name of a whole embedded object, e.g. device
message=gensub( /" *:( *)"([^"]+)"( *[,}]+)/ , "\":\\1\"XXwhiteXX\\2XXwhiteXX\"\\3" , "g", message) # highlight a quoted string value in JSON
message=gensub( /" *:( *)(null|-{0,1}([0-9]*[.]{0,1}[0-9]*))( *[,}]+)/ , "\":\\1XXwhiteXX\\2XXwhiteXX\\4 " , "g", message) # highlight a numeric value in JSON
message=gensub( / *, *"/ , ", \"" , "g", message) # reduce spaces around a comma to max one
message=gensub( /([,{] *)"([^"]+)"/ , "\\1XXnoneXX\\2XXnoneXX" , "g", message) # make keys yellow and remove apostrophes
message=gensub( /" *:( *)(null|-{0,1}([0-9]*[.]{0,1}[0-9]*))( *[,}]+)/ , "\":\\1XXyellowXX\\2XXyellowXX\\4 " , "g", message) # highlight a numeric value in JSON
message=gensub( / *, *"/ , ", \"" , "g", message) # reduce spaces around a comma to max one
message=gensub( /([,{] *)"([^"]+)"/ , "\\1XXnoneXX\\2XXnoneXX" , "g", message) # highlight keys and remove apostrophes around keys
gsub(/\"act_t\" *:/, "\"action_topic\":", message)
gsub(/\"act_tpl\" *:/, "\"action_template\":", message)
Expand Down Expand Up @@ -426,7 +427,7 @@ gsub(/\"xy_val_tpl\" *:/, "\"xy_value_template\":", message)
| GREP_COLOR="$grey" $stdbufcmd grep $GREPOPTS -E -e "^" -e " \{|,|\}$" \
| GREP_COLOR="$white" $stdbufcmd grep $GREPOPTS -E -e "^" -e 'XXwhiteXX[^X]+XXwhiteXX' \
| GREP_COLOR="$cyan" $stdbufcmd grep $GREPOPTS -E -e "^" -e 'XXcyanXX[^:]+XXcyanXX' \
| awk -- '{ gsub( "XXcol1timeXX|XXbeginofredXX|XXendofredXX|XXbeginofpurpleXX|XXendofpurpleXX|XXwhiteXX|XXcyanXX|XXyellowXX|XXnoneXX" , "" ); print }' ; \
| awk -- '{ gsub( "XXcol1timeXX|XXbeginofredXX|XXendofredXX|XXbeginofpurpleXX|XXendofpurpleXX|XXwhiteXX|XXcyanXX|XXyellowXX|XXnoneXX" , "" ); print }' \
;
else
cat
Expand Down

0 comments on commit 8411fd9

Please sign in to comment.