Eu tenho um arquivo de log trace.log
que imprime o registro de data e hora, o nome do segmento, o método de transação e o ID da transação, conforme abaixo.
2014-01-23 15:50:41,724 [catalina-exec-35] INFO TRANSACTION getConnection REQUEST, ID=1308::
2014-01-23 15:50:41,725 [catalina-exec-33] INFO TRANSACTION getConnection REQUEST, ID=1304::
2014-01-23 15:50:41,727 [catalina-exec-10] INFO TRANSACTION getConnection REQUEST, ID=1298::
2014-01-23 15:50:41,727 [catalina-exec-24] INFO TRANSACTION getConnection REQUEST, ID=1307::
2014-01-23 15:50:41,727 [catalina-exec-12] INFO TRANSACTION getConnection DONE, ID=1305::
2014-01-23 15:50:41,733 [catalina-exec-10] INFO TRANSACTION getConnection DONE, ID=1298::
2014-01-23 15:50:41,734 [catalina-exec-26] INFO TRANSACTION getConnection REQUEST, ID=1313::
2014-01-23 15:50:41,734 [catalina-exec-26] INFO TRANSACTION getConnection DONE, ID=1313::
2014-01-23 15:50:41,738 [catalina-exec-39] INFO TRANSACTION getConnection REQUEST, ID=1311::
2014-01-23 15:50:41,733 [catalina-exec-35] INFO TRANSACTION getConnection DONE, ID=1308::
2014-01-23 15:50:41,738 [catalina-exec-27] INFO TRANSACTION getConnection REQUEST, ID=1309::
2014-01-23 15:50:41,737 [catalina-exec-22] INFO TRANSACTION getConnection REQUEST, ID=1310::
2014-01-23 15:50:41,743 [catalina-exec-30] INFO TRANSACTION getConnection REQUEST, ID=1315::
2014-01-23 15:50:41,744 [catalina-exec-39] INFO TRANSACTION getConnection DONE, ID=1311::
2014-01-23 15:50:41,747 [catalina-exec-2] INFO TRANSACTION getConnection REQUEST, ID=1318::
Eu quero grep
e imprimo a data e hora de getConnection REQUEST
e getConnection DONE
para uma ID específica em uma única linha em um arquivo.
Eu escrevi um script de shell que imprime o registro de data e hora em várias linhas, conforme abaixo.
Aqui está o meu script de shell
for i in {1..800}
do
echo "Welcome $i times"
echo "ID=$i, getConnection " >> time.log
grep ID=$i: trace.log | grep getConnection | cut -d'[' -s -f1 >> time.log
echo " " >> time.log
done
A saída é como mostrado abaixo
ID=791, getConnection
2014-01-23 15:50:16,703
2014-01-23 15:50:16,706
ID=792, getConnection
2014-01-23 15:50:16,704
2014-01-23 15:50:16,704
ID=793, getConnection
2014-01-23 15:50:16,704
2014-01-23 15:50:16,709
ID=794, getConnection
2014-01-23 15:50:16,708
2014-01-23 15:50:16,712
Como posso mudar isso? Eu preciso de saída como mostrado abaixo:
ID=792, getConnection 2014-01-23 15:50:16,703 2014-01-23 15:50:16,706
ID=792, getConnection 2014-01-23 15:50:16,704 2014-01-23 15:50:16,704
ID=793, getConnection 2014-01-23 15:50:16,704 2014-01-23 15:50:16,709
ID=794, getConnection 2014-01-23 15:50:16,708 2014-01-23 15:50:16,712