Grep sobre vários arquivos, ordenar por saída

0

Estou usando o grep para pesquisar vários arquivos de log. No log, cada linha tem a hora no formato hh: mm: ss como a primeira parte. Este horário deve ser o critério de classificação.

Se eu estiver usando grep -r string1 | grep --color string2 | sort , a classificação será aplicada ao nome do arquivo (que é uma informação útil), adicionar o parâmetro -n torna as coisas ainda piores, já que o número de linha incluído será usado.

Os registros têm um formato assim:

354058:c1.com/client-01.log:13:30:04 INFO:       Item: created widget in ARRIVALS
360746:c1.com/client-01.log:13:39:46 INFO:          change transfer to contact
379144:c3.com/client-01.log:13:30:02 INFO:       Item: created widget in ARR
392162:c3.com/client-01.log:13:51:59 INFO:       Item: created widget in ARR
367422:c5.com/client-01.log:13:51:56 INFO:       searching for Sign 
367446:c5.com/client-01.log:13:51:59 INFO:       Item: created widget in ARRIVALS
367629:c5.com/client-01.log:13:52:12 INFO:          change from initial to contact
371979:c9.com/client-01.log:14:00:19 INFO:          change workflow to tgl

Editar: O tipo que eu espero ser é:

379144:c3.com/client-01.log:13:30:02 INFO:       Item: created widget in ARR
354058:c1.com/client-01.log:13:30:04 INFO:       Item: created widget in ARRIVALS
360746:c1.com/client-01.log:13:39:46 INFO:          change transfer to contact
367422:c5.com/client-01.log:13:51:56 INFO:       searching for Sign 
392162:c3.com/client-01.log:13:51:59 INFO:       Item: created widget in ARR
367446:c5.com/client-01.log:13:51:59 INFO:       Item: created widget in ARRIVALS
367629:c5.com/client-01.log:13:52:12 INFO:          change from initial to contact
371979:c9.com/client-01.log:14:00:19 INFO:          change workflow to tgl

Com a alteração sugerida e o acréscimo de | sort -t'/' -k2V a maioria dos resultados parece razoável, ainda assim eu obtive algo assim do nada, enquanto a maioria dos outros resultados está perfeitamente bem.

353619:d1.com/core-01.log:14:09:45 INFO:          Server: updating
33:c5.com/client-01.log:13:30:02 INFO:       Item: created widget in ACTIVE
    
por Qohelet 26.04.2018 / 11:14

1 resposta

1

Dado o arquivo

354058:c1.com/client-01.log:13:30:04 INFO:       Item: created widget in ARRIVALS
360746:c1.com/client-01.log:13:39:46 INFO:          change transfer to contact
379144:c3.com/client-01.log:13:30:02 INFO:       Item: created widget in ARR
392162:c3.com/client-01.log:13:51:59 INFO:       Item: created widget in ARR
353619:d1.com/core-01.log:14:09:45 INFO:          Server: updating
367422:c5.com/client-01.log:13:51:56 INFO:       searching for Sign
367446:c5.com/client-01.log:13:51:59 INFO:       Item: created widget in ARRIVALS
367629:c5.com/client-01.log:13:52:12 INFO:          change from initial to contact
371979:c9.com/client-01.log:14:00:19 INFO:          change workflow to tgl

o comando

sort -t: -k3 file

executaria uma ordenação lexicográfica usando o terceiro campo : -delimited (e qualquer coisa depois dele) como a chave de classificação. O resultado seria

379144:c3.com/client-01.log:13:30:02 INFO:       Item: created widget in ARR
354058:c1.com/client-01.log:13:30:04 INFO:       Item: created widget in ARRIVALS
360746:c1.com/client-01.log:13:39:46 INFO:          change transfer to contact
367422:c5.com/client-01.log:13:51:56 INFO:       searching for Sign
392162:c3.com/client-01.log:13:51:59 INFO:       Item: created widget in ARR
367446:c5.com/client-01.log:13:51:59 INFO:       Item: created widget in ARRIVALS
367629:c5.com/client-01.log:13:52:12 INFO:          change from initial to contact
371979:c9.com/client-01.log:14:00:19 INFO:          change workflow to tgl
353619:d1.com/core-01.log:14:09:45 INFO:          Server: updating

Para que isso funcione, supõe-se que os números nos campos 3, 4 e 5 sejam sempre preenchidos com zeros.

    
por 26.04.2018 / 12:07

Tags