Imprimir texto por string

1

Eu tenho essa saída no arquivo de texto, da cassandra-cli. Preciso imprimir RowKey e OnlineUsers , estou usando bash e grep não funciona.

Column Family assumptions read from /root/.cassandra/assumptions.json
Welcome to Cassandra CLI version 1.2.19

Type 'help;' or '?' for help.
Type 'quit;' or 'exit;' to quit.

[default@unknown] use Agent;
Authenticated to keyspace: Agent
[default@Agent] list VCCs;
Using default limit of 100
Using default cell limit of 100
-------------------
RowKey: cienciaactiva
=> (name=AllegroIntegration, value={"enabled":true}, timestamp=1504725823694867)
=> (name=CALL_licensed, value=1, timestamp=1504725823700706)
=> (name=CHAT_licensed, value=1, timestamp=1504725823695468)
=> (name=Id, value=cienciaactiva, timestamp=1504725823696915)
=> (name=IsSystemVCC, value=0, timestamp=1504725823699902)
=> (name=MAIL_licensed, value=1, timestamp=1504725823699520)
=> (name=OnlineUsers, value=1, timestamp=1504725823698413)
=> (name=WEBCONTACT_licensed, value=1, timestamp=1504725823697610)
-------------------
RowKey: atento
=> (name=CHAT_licensed, value=0, timestamp=1459855264796678)
=> (name=Id, value=atentoperusedapal, timestamp=1459855264801483)
=> (name=IsSystemVCC, value=1, timestamp=1459855264802006)
=> (name=MAIL_licensed, value=0, timestamp=1459855264797787)
=> (name=OnlineUsers, value=5, timestamp=1459855264796155)
=> (name=WEBCONTACT_licensed, value=0, timestamp=1459855264803923)
-------------------
RowKey: tsc
=> (name=CHAT_licensed, value=0, timestamp=1464217813009934)
=> (name=Id, value=tsc, timestamp=1464217813012789)
=> (name=IsSystemVCC, value=1, timestamp=1464217813016091)
=> (name=MAIL_licensed, value=1, timestamp=1464217813010988)
=> (name=OnlineUsers, value=7, timestamp=1485884014708000)
=> (name=WEBCONTACT_licensed, value=0, timestamp=1464217813012116)

3 Rows Returned.
Elapsed time: 178 msec(s).
[default@Agent]

O resultado esperado seria algo como:

RowKey: cienciaactiva
name=OnlineUsers, value=1
-------------------
RowKey: atento
name=OnlineUsers, value=5
-------------------
RowKey: tsc
name=OnlineUsers, value=7
    
por Alvaro Maravi 06.02.2018 / 17:53

2 respostas

1

Com o comando awk :

awk '/RowKey/; /name=OnlineUsers/{ 
        print substr($2, 2), substr($3, 1, length($3)-1); f=1 
     }f && /---/' file

A saída:

RowKey: cienciaactiva
name=OnlineUsers, value=1
-------------------
RowKey: atento
name=OnlineUsers, value=5
-------------------
RowKey: tsc
name=OnlineUsers, value=7
    
por 06.02.2018 / 18:07
0

grep deve estar bem para este fim:

$ grep -e '^RowKey:' -e name=OnlineUsers -e '^----' input
-------------------
RowKey: cienciaactiva
=> (name=OnlineUsers, value=1, timestamp=1504725823698413)
-------------------
RowKey: atento
=> (name=OnlineUsers, value=5, timestamp=1459855264796155)
-------------------
RowKey: tsc
=> (name=OnlineUsers, value=7, timestamp=1485884014708000)

Se você precisar remover timestamps de OnlineUsers , você pode fazer isso facilmente com o GNU awk :

$ awk -F '[(,]' '/^RowKey:/ || /^----/ { print } /name=OnlineUsers/ { print $2 "," $3 }' input
-------------------
RowKey: cienciaactiva
name=OnlineUsers, value=1
-------------------
RowKey: atento
name=OnlineUsers, value=5
-------------------
RowKey: tsc
name=OnlineUsers, value=7
    
por 06.02.2018 / 18:02