Как удалить информацию журнала (TimeStamp и т. Д.) Из файла журнала - PullRequest
0 голосов
/ 04 апреля 2019

У меня есть файл журнала, который содержит такие вещи, как:

2019-04-03 22:30:16,772 [pool-9-thread-1] INFO  wire.CampaignManagement: --> POST https://foo.com
2019-04-03 22:30:16,772 [pool-9-thread-1] INFO  wire.CampaignManagement: Content-Type: application/json; charset=UTF-8
2019-04-03 22:30:16,772 [pool-9-thread-1] INFO  wire.CampaignManagement: Content-Length: 893
2019-04-03 22:30:16,772 [pool-9-thread-1] INFO  wire.CampaignManagement: x-foo-id:blah
2019-04-03 22:30:16,772 [pool-9-thread-1] INFO  wire.CampaignManagement: Authorization: Bearer ***
2019-04-03 22:30:16,772 [pool-9-thread-1] INFO  wire.CampaignManagement: 
2019-04-03 22:30:16,772 [pool-9-thread-1] INFO  wire.CampaignManagement: {"url_tags":"utm_campaign"}
2019-04-03 22:30:16,772 [pool-9-thread-1] INFO  wire.CampaignManagement: --> END POST (893-byte body)
2019-04-03 22:30:16,772 [pool-9-thread-1] INFO  wire.CampaignManagement: <-- 400 Bad Request https://foo.com (4443ms)
2019-04-03 22:30:16,772 [pool-9-thread-1] INFO  wire.CampaignManagement: Vary: Accept-Encoding
2019-04-03 22:30:16,772 [pool-9-thread-1] INFO  wire.CampaignManagement: x-aax_id: 555
2019-04-03 22:30:16,772 [pool-9-thread-1] INFO  wire.CampaignManagement: x-app-usage: {"call_count":0,"total_cputime":0,"total_time":0}
2019-04-03 22:30:16,772 [pool-9-thread-1] INFO  wire.CampaignManagement: WWW-Authenticate: OAuth "invalid_request" "Invalid parameter"
2019-04-03 22:30:16,772 [pool-9-thread-1] INFO  wire.CampaignManagement: Content-Type: text/javascript; charset=UTF-8
2019-04-03 22:30:16,772 [pool-9-thread-1] INFO  wire.CampaignManagement: version: v0.122
2019-04-03 22:30:16,772 [pool-9-thread-1] INFO  wire.CampaignManagement: Pragma: no-cache
2019-04-03 22:30:16,772 [pool-9-thread-1] INFO  wire.CampaignManagement: x-xxx-aaa: 123475
2019-04-03 22:30:16,772 [pool-9-thread-1] INFO  wire.CampaignManagement: Access-Control-Allow-Origin: *
2019-04-03 22:30:16,772 [pool-9-thread-1] INFO  wire.CampaignManagement: Cache-Control: no-store
2019-04-03 22:30:16,772 [pool-9-thread-1] INFO  wire.CampaignManagement: x-aa_id: bfi742bfsa
2019-04-03 22:30:16,772 [pool-9-thread-1] INFO  wire.CampaignManagement: Expires: Sat, 01 Jan 2000 00:00:00 GMT
2019-04-03 22:30:16,772 [pool-9-thread-1] INFO  wire.CampaignManagement: Date: Wed, 03 Apr 2019 22:30:16 GMT
2019-04-03 22:30:16,772 [pool-9-thread-1] INFO  wire.CampaignManagement: Connection: keep-alive
2019-04-03 22:30:16,772 [pool-9-thread-1] INFO  wire.CampaignManagement: 
2019-04-03 22:30:16,772 [pool-9-thread-1] INFO  wire.CampaignManagement: {"error":{"message":"Invalid parameter"}}
2019-04-03 22:30:16,772 [pool-9-thread-1] INFO  wire.CampaignManagement: <-- END HTTP (294-byte body)

Есть ли способ удалить все вхождения 2019-04-03 22:30:16,772 [pool-9-thread-1] INFO wire.CampaignManagement: с помощью команд Linux?

Примечание: я работаю на удаленной машине, поэтому я не могу использовать VSCode или Sublime для редактирования этого материала.

Ответы [ 2 ]

0 голосов
/ 04 апреля 2019

То же, что и @Gilles Quenot: sed.

В качестве примера частично более универсальной версии (хотя и не элегантной) ее можно использовать вместо:

   sed 's/[[:digit:]]\{4\}-[[:digit:]]\{2\}-[[:digit:]]\{2\} [[:digit:]]\{1,2\}:[[:digit:]]\{1,2\}:[[:digit:]]\{1,2\},[[:digit:]]\{1,3\} \[pool-9-thread-1\] \(INFO\|DEBUG\)  wire.CampaignManagement://' file

Если протектор, уровень журнала или имя могут быть изменены, сопоставьте его соответственно.

0 голосов
/ 04 апреля 2019

С :

perl -i -pe 's/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2},\d{3}\d+\[pool-\d+-thread-\d+\]\d+(?:INFO|DEBUG)\d+wire\.CampaignManagement://'  file
...