AWK divide a saída com a linha

1

Como posso dividir linhas de saída usando tailf e awk assim?

A partir disso:

tail -f logfile.log | awk '/connected/ {print "3[31m" $0 "3[39m"}'

Saída:

2018-01-31 10:00 user connected autentication successful
2018-01-31 10:10 user connected autentication successful
2018-01-31 10:23 user connected autentication successful
2018-01-31 10:34 user connected autentication unsuccessful
2018-01-31 10:35 user connected autentication unsuccessful

Para esta saída:

2018-01-31 10:00 user connected autentication successful
----------------------------------------------------------
2018-01-31 10:10 user connected autentication successful
----------------------------------------------------------
2018-01-31 10:23 user connected autentication successful
----------------------------------------------------------
2018-01-31 10:34 user connected autentication unsuccessful
----------------------------------------------------------
2018-01-31 10:35 user connected autentication unsuccessful

Obrigado antecipadamente!

    
por Ramin Ismayilli 31.01.2018 / 08:50

2 respostas

2

Se você quiser que as linhas separadoras sejam brancas:

tail -f logfile.log | awk '/connected/ {print "3[31m" $0 "3[39m\n-----------------------------------"}'

Se você quiser que a linha de separação seja vermelha:

tail -f logfile.log | awk '/connected/ {print "3[31m" $0 "\n-----------------------------------3[39m"}'
    
por ReineS 31.01.2018 / 09:35
0

Se tudo o que você quiser fazer é imprimir ---------------------------------------------------------- após cada linha, defina o ORS (separador de registro de saída) para o que você quiser depois de cada linha:

$ awk -v ORS='3[39m\n----------------------------------------------------------\n' '/connected/ {print "3[31m" $0}' foo
2018-01-31 10:00 user connected autentication successful
----------------------------------------------------------
2018-01-31 10:10 user connected autentication successful
----------------------------------------------------------
2018-01-31 10:23 user connected autentication successful
----------------------------------------------------------
2018-01-31 10:34 user connected autentication unsuccessful
----------------------------------------------------------
2018-01-31 10:35 user connected autentication unsuccessful
----------------------------------------------------------

Aqui, movi o 3[39m para o ORS do comando print e rodei os hifens com novas linhas ( \n ).

    
por muru 31.01.2018 / 09:32