Loading...

I got this situation in a log file, where the JSON information is after the grep output of the file name.

hsm_127.0.0.1-2017-10-10.log:{"datetime":"2017-10-10T00:00:00.705+0200","level":"INFO","logger":"com.example.ee7.restserver.RequestStatisticsLogger","logmessage":"Processed POST http://127.0.0.1:11480/hss-web/v0/ic/4711 with status=200 in 38ms","class":"com.example.ee7.restserver.RequestStatisticsLogger","method":"filter","line_number":0,"tags":[""],"environment":"prd","application":"hsm","version":"1.0.92","thread":"default task-251","BOX-ID":"apslhsmpci08","duration":"38","request-method":"POST","APP-ID":"PayMe","response-status":"200","request-uri":"/ic/530","IC-ID":"530"}

To search and replace it with an empty string. The option (c) requires an interactive confirmation.

:%s/hsm_127.0.0.1-2017-10-10.log\://gc

Just search and replace

%s/hsm_127.0.0.1-2017-10-10.log\://g

Use wildcards

What do you do if you more timestamps inside the logfile? Therefore you can use regular expression wild cards.

Develop regex pattern with this online editor.

Regular Expression Debugger

To test if the regex matches, count matches the option n

%s/hsm_\([0-9.-]*\).log\://gn

To replace all occurences

%s/hsm_\([0-9.-]*\).log\://g