文字列でテキストを印刷する

文字列でテキストを印刷する

この出力はcassandra-cliのテキストファイルとして表示されます。印刷する必要があるのでRowKey使用しOnlineUsersています。強く打つ、そしてgrep動作しません。

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]

予想される出力は次のようになります。

RowKey: cienciaactiva
name=OnlineUsers, value=1
-------------------
RowKey: atento
name=OnlineUsers, value=5
-------------------
RowKey: tsc
name=OnlineUsers, value=7

ベストアンサー1

そしてawk注文する:

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

出力:

RowKey: cienciaactiva
name=OnlineUsers, value=1
-------------------
RowKey: atento
name=OnlineUsers, value=5
-------------------
RowKey: tsc
name=OnlineUsers, value=7

おすすめ記事